Lowest Common Ancestor
Learn Lowest Common Ancestor (Trees, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
What is LCA? The Lowest Common Ancestor of two nodes p and q is the DEEPEST node that has BOTH p and q as descendants (a node is considered a descendant of itself). For a general binary tree, find it with a bottom-up recursive search: a node IS the LCA if p and q are found in DIFFERENT subtrees (or the node itself is p or q).
More lessons in Trees
- Binary Tree
- Binary Search Tree - BST
- Full / Complete / Perfect Binary Tree
- Balanced Tree
- Tree Traversal - Preorder
- Tree Traversal - Inorder
- Tree Traversal - Postorder
- Tree Traversal - Level Order
- Recursive Traversal
- Iterative Traversal
- Height / Depth
- Diameter of a Tree
- Path Sum
- Tree View - Left View
- Tree View - Right View
- Tree View - Top View
- Tree View - Bottom View
- Boundary Traversal
- Vertical Traversal
- Zigzag Traversal
- Serialize / Deserialize a Tree
- BST Operations
- BST Validation
- Kth Smallest / Largest in BST
- Morris Traversal