Given the following (sorted) array with distinct integer elements, write an algorithm to construct a balanced binary search tree.
What is the maximum depth of the tree?
[1, 2, 3, 5, 8, 9,10, 11, 13, 14, 16, 17,18, 19, 20, 25, 40, 39, 100, 560]
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
there are 20 elements...easiest way to get the answer is:
First node: 20/2=10
second node: 10/2=5
third node: (5+1)/2=3 since 5 is odd
fourth node:(3+1)/2=2 since 3 is odd
fifth node: (2/2)=1
so the depth becomes 5 nodes.