Question:
How to find median of a BST?
Answer:
Find the no. of elements on the left side. If it is n-1 the root is the median. If it is more than n-1, then it has already been found in the left subtree. Else it should be in the right subtree.
Source: CoolInterview.com
Its better to count all the elements in the tree in one traversal and then use inorder traversal to print the n/2th element in second traversal. Source: CoolInterview.com
Answered by: game | Date: 2/7/2010
| Contact game
Its simply the ROOT of the tree, with a condition that the tree is Sorted and has equal number of nodes on both sides - left and right. Source: CoolInterview.com
Answered by: Pinki Ruparel | Date: 3/4/2010
| Contact Pinki Ruparel
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|