You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Find the middle element in array. This element will be the root
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.
The text was updated successfully, but these errors were encountered:
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:
Solution
The text was updated successfully, but these errors were encountered: