Friday, March 8, 2013

[Cracking the Code Interview 4th Edition] 4.5

Write an algorithm to find the 'next' node (in-order successor) of a given node in a binary search tree where each node has a link to its parent.

Thought:
If it is root, find the leftmost right child.
If it has right child, find the leftmost right child.
If it has no right child and has parent, go up until this node is left child of its parent. Find that parent.

No comments:

Post a Comment