Wednesday, December 30, 2009

How to find median of a BST?

If the no of keys are odd, there will be only one median, if it is even there will be two median.
  • Execute two InOrder traversal, the first one runs as the double speed the second one. It means the first one visits two nodes while the second one visits one nodes. So when the first one finish traverse, the second one point the mid value!

No comments:

Post a Comment

Search Ranjeet's Blog