Skip to content

Create a balanced binary search tree from a sorted array. #2706

@kumanoit

Description

@kumanoit

Create a balanced binary search tree from a sorted array.
Given a sorted array like [1,2,3,4,5] .Create a binary search tree out of it.
The tree will look like:

                             3
                        /        \
                    2             5
                 /                 /
               1                 4

Solution

  1. Find the middle element in array. This element will be the root
  2. Recursively do for the left and right part of array and set left child of above root to subtree returned from left part of array. similarly for the right part.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions