Horje

FINDING lowest common ancestor - Lowest common ancestor of a Binary Tree - Algorithm
Learn
Algorithm - Lowest common ancestor of a Binary Tree - Finding lowest common ancestor
Finding lowest common ancestor

Consider the tree:

enter image description here (opens new window)

Lowest common ancestor of nodes with value 1 and 4 is 2

Lowest common ancestor of nodes with value 1 and 5 is 3

Lowest common ancestor of nodes with value 2 and 4 is 4

Lowest common ancestor of nodes with value 1 and 2 is 2

Read Article
https://develop.horje.com/learn/1434/reference