Given a binary tree, write an algorithm to find the first common ancestor of any two nodes
Answers
Answered by
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
Hindi,
5 months ago
Social Sciences,
5 months ago
Computer Science,
10 months ago
Computer Science,
10 months ago
Math,
1 year ago
Biology,
1 year ago
World Languages,
1 year ago