Module 8 · Graphs and Trees · Binary Tree

Lowest common ancestor

Each call answers one question for its subtree: did you find p or q? A node whose left and right subtrees both say yes is the lowest common ancestor; otherwise it passes up whatever it found.

Under a finished node of tree is what its call returned.