Given a binary tree and two nodes. Find Least Common Ancestor (LCA) of the two nodes. For example given the tree T below. LCA(T, 5, 6) = 3, LCA(T, 4, 6) = 1, etc. 1 / \ 2 3 / / \ 4 5 6 \ / 7 8 With parent pointer If we are […]
Tag Archives: lca
Given two nodes in a binary tree with parent pointer. Find the min path from between two nodes. Note that root of the tree is not given Let’s start with an example as follows. 1 / \ 2 3 / / \ 4 5 6 \ / 7 8 Use parent pointer to find the […]