AlgoScope

Lowest Common Ancestor

AlgorithmintermediateBST Operationsalso called LCA

Walk down while both values are on the same side. Where they split is the answer.

Decision · step 2 of 4BST Queries: Lowest common ancestor
2030354050✓607080current

Both 20 and 40 are smaller than 50, so both live to the left. Go left.

Open in the player →or start at step 2

What you will see

Focus descends until the two targets part ways.

How bst queries works →

Cost

BestO(1)
AverageO(log n)
WorstO(n)
SpaceO(1)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, try operations in any order.

Screen readers: Nodes announce value, left child and right child; each step announces the comparison and the direction taken or the structural change.

Reduced motion: Focus jumps node to node with a static ring; rotations become a crossfade between the two layouts.

Before this

Taught by the same lesson

BST Queries covers these too, in the same run.