Purpose: The first -preprocessing, -query algorithm for Lowest Common Ancestor (1984) — the result that established LCA as a constant-time operation.

The Idea: compressed trees and bit tricks

  1. Heavy path decomposition. Partition the tree into paths so that any root-to-leaf walk crosses paths. (The same decomposition later popularised as HLD.)
  2. Complete binary tree embedding. Map the compressed structure into a complete binary tree, where LCA has a closed form: for nodes with inorder labels and , the LCA label is obtained from the highest bit where and differ — a single XOR and a clz.
  3. Bit-encoded ancestor sets. Each node stores a machine word whose bits record which of the path levels contain an ancestor. Combining two such words with bitwise operations locates the correct path in .

Queries become a fixed sequence of shifts, XORs and leading-zero counts — no lookups into large tables.

Complexity

  • Preprocessing:
  • Query:
  • Space: words

Historical significance

Before Harel-Tarjan, LCA was thought to require a logarithmic factor. Their paper showed constant time was achievable and triggered a sequence of simplifications:

YearResultApproach
1984Harel-Tarjancompressed trees + bit tricks; correct but hard
1988Schieber-Vishkinsimplified, parallelisable, still bit-trick based
1993Berkman-Vishkinreduction to ±1 RMQ
2000Farach-Colton-Bender±1 RMQ + four Russians; the standard exposition
2004Bender-Farach-Coltonfurther simplification, sparse table on blocks
Tarjan offline with DSU, if queries are known in advance

What to actually use

NeedUse
LCA only, simple codeEuler tour + sparse table
LCA + -th ancestor + path aggregatesBinary lifting
All queries known in advanceTarjan offline
Path updates and queriesHLD + segment tree
Truly need preprocessingFarach-Colton-Bender

In practice, binary lifting is the right default: it is 20 lines, and per query is never the bottleneck.

Variants / Use Cases

  • Lowest Common Ancestor — the topic page with code
  • Level ancestor problem — a related result (Bender-Farach-Colton, via ladder decomposition)
  • Distance in trees; the single most common use of LCA
  • HLD — the decomposition Harel and Tarjan introduced here, now famous for a different reason