Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kumanoit opened this issue Oct 23, 2021 · 1 comment
Closed

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

kumanoit opened this issue Oct 23, 2021 · 1 comment
Assignees

Comments

@kumanoit
Copy link
Contributor

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.
@kumanoit
Copy link
Contributor Author

Please assign this to me.

kumanoit pushed a commit to kumanoit/Java that referenced this issue Oct 23, 2021
@siriak siriak closed this as completed in 64513ff Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant