algorithms.tutorialhorizon.com

Find the Distance between Two Nodes of a Binary Tree. | Algorithms

Find the Distance between Two Nodes of a Binary Tree. Distance(X, Y) = Distance(root, X) +Distance(root, Y) - 2*(Distance(root to LCA(X,Y) where LCA(X,Y) = Lowest Common Ancestor of X,Y