Thursday, July 15, 2010

Nth largest number in the BST

Find the Nth largest number in the binary search tree?
Suppose there are seven elements in the BST as shown below.

    23

   / \

  15 30

 / \ / \

7 18 27 33

Then 5th largest element is 18.