problemmediumalgorithmslowest-common-ancestor-lca-definitionlowest common ancestor lca definitionlowestcommonancestorlcadefinition

Lowest Common Ancestor Definition

MediumUpdated: Aug 2, 2025

Problem

Definition

According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes p and q as the lowest node in T that has both p and q as descendants (where we allow a node to be a descendant of itself).”

Examples

graph TD;
	6;
	6 --- 2;
	6 --- 8;
	2 --- 0;
	2 --- 4;
	8 --- 7;
	8 --- 9;
	4 --- 3;
	4 --- 5;
  • LCA of 2 and 8 is 6
  • LCA of 2 and 4 is 2

Problems

Binary Tree

[Lowest Common Ancestor of a Binary Tree](lowest-common-ancestor-of-a-binary-tree) [Lowest Common Ancestor of a Binary Tree 2 - Nodes may not exist in Tree](lowest-common-ancestor-of-a-binary-tree-2-nodes-may-not-exist-in-tree) [Lowest Common Ancestor of a Binary Tree 3 - Given Parent Pointer](lowest-common-ancestor-of-a-binary-tree-3-given-parent-pointer) [Lowest Common Ancestor of a Binary Tree 4 - for array of nodes](lowest-common-ancestor-of-a-binary-tree-4-for-array-of-nodes)

BST

[Lowest Common Ancestor of a Binary Search Tree](lowest-common-ancestor-of-a-binary-search-tree)

N-Ary Tree

[Lowest Common Ancestor for a n-ary Tree](lowest-common-ancestor-for-a-n-ary-tree)

Comments