N-ary tree case

Can you please explain how could we solve lca problem for n-ary tree? Could you please send some resource.

There are several methods to find lca in n-ary tree.
Method 1: Do recursive calls similar to finding lca in binary tree. If you both nodes are coming ffrom the same node ( node->left,node_right, etc) go to that node. else if any two node returns true then that is the answer.
Method 2: Do a tree traversal storing the parent pointer. Now get the path from each node to root node using the parent pointer. The first common node in both the path will be the LCA.

1 Like

Thank you.Can you please explain the bottom up approach as explained in the video?

Explanation of video.


The soln explained in the video is top down ig.
Bottom up/ iterative : https://ide.codingblocks.com/s/226689

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.