Skip to content
DSA Visualizerpreview

Lowest common ancestor (BST)

Walk down from the root until the two values stop being on the same side.

O(h) time · O(1) space

Values50, 30, 70, 20, 40, 60, 80, 35, 45p, q 35, 45

Find the lowest common ancestor of 35 and 45.

Tree with 9 nodes; in order: 20, 30, 35, 40, 45, 50, 60, 70, 80.
  • compare
  • swap or write
  • settled

1 / 4

Speed

Space play · ← → step · Home End jump · drag the strip to scrub