Computer Science, asked by Akritisingh9894, 10 months ago

Given a binary tree, write an algorithm to find the first common ancestor of any two nodes

Answers

Answered by gauravarduino
1

Answer:

Following are different approaches to find LCA in Binary Tree. Method 1 (By Storing root to n1 and root to n2 paths): 1) Find path from root to n1 and store it in a vector or array. 2) Find path from root to n2 and store it in another vector or array. 3) Traverse both paths till the values in arrays are same.

Similar questions