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