← CS_basics
Visualizer
/
Lowest Common Ancestor
🌙
Lowest Common Ancestor (LCA)
Post-order DFS: bubble up p/q; first node holding both is LCA. LC 236, 235, 1123, 1676.
Unvisited
Current DFS
Target node (p or q)
Carries result up
LCA found
Controls
Target p:
3
Target q:
5
Speed
Find LCA
Reset
Time: O(n) | Post-order DFS
Steps