Binary search

The following numbers are inserted into an empty binary search tree in the given order: 11, 2, 4, 5, 15, 13, 16. What is the height of this binary search tree?

Assume the height of a tree is the number of edges on the longest downward path between the root and a leaf.


The answer is 3.

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.

1 solution

Geoff Pilling
Feb 11, 2017

They would get inserted as follows:

  • 11 ( l e f t ) 2 11 (left) \to 2
  • 2 ( r i g h t ) 4 2 (right) \to 4
  • 4 ( r i g h t ) 5 4 (right) \to 5
  • 11 ( r i g h t ) 15 11 (right) \to 15
  • 15 ( l e f t ) 13 15 (left) \to 13
  • 15 ( r i g h t ) 16 15 (right) \to 16

So, the longest one is:

11 2 4 5 11 \to 2 \to 4 \to 5

So, its height is 3 \boxed3

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...