Overview
Tarjan's offline LCA processes all queries together, merging completed subtrees with union-find so each query can be answered when both endpoints have been visited.
Answers lowest-common-ancestor queries in a tree using DFS and union-find.
Compact metadata for implementation and discovery.
Tarjan's offline LCA processes all queries together, merging completed subtrees with union-find so each query can be answered when both endpoints have been visited.
Quick facts
Runtime and memory behavior at a glance.
Best
O((n + q) alpha(n))
Average
O((n + q) alpha(n))
Worst
O((n + q) alpha(n))
Space
O(n + q)
ancestor[find(v)] = current_ancestorStores the current ancestor for each completed union-find set.
Highlight active nodes, discovered edges, and the graph structure produced by each step.
Tarjan's Offline LCA should be used with the assumptions and tradeoffs of offline Tree Queries in mind.
What each reference supports for this entry.
Textbook support for Tarjan's Offline LCA's standard algorithm design, invariants, and complexity analysis.
Open sourceAlgorithm catalog support for Tarjan's Offline LCA's problem context, known alternatives, and practical selection tradeoffs.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Tarjan's offline LCA answers ancestor queries by combining DFS traversal with union-find sets.