binary-treedepth-first-searchlowest-common-ancestor

What is the lowest common ancestor of 5 and 4 in this binary tree


Binary tree

Binary tree

What is the lowest common ancestor of 5 and 4 in the binary tree above, considering we allow a node to be a descendant of itself. Wouldn't it be 3? if not, what would it be and why?


Solution

  • As we allow a node to be a descendant of itself, LCA will be 5.