Microsoft Interview Question

find common ancestor in binary tree

Interview Answers

Anonymous

Mar 13, 2011

1. Start from the root node of the tree. 2. Check that the value of both the nodes to be compared should be either more than, or less than the root node. 2a. If its more than the root, then traverse to the right child node, and check the same condition. 2b. If its less than the root, then traverse to the left child node, and check the same condition. 3. Keep recursing until you find the node where this condition is falsified.

Anonymous

Apr 2, 2011

@MrB The question is about a Binary Tree, not a Binary Search Tree.