take root as the start node and do a DFS traversal on this tree. This can be done in linear time. DFS traversal will give [entry time, exit time] for each node. Now do an inorder traversal of the tree to find the first node such that the entry & exit time of both the input nodes (whose ancestor we r trying to find) is nested within this node. This node is the required ancestor
On Jun 17, 6:00 am, jalaj jaiswal <jalaj.jaiswa...@gmail.com> wrote: > write an algo which gives the lowest common ancestor of two nodes in a > general tree(not binary specifically) > > -- > With Regards, > Jalaj Jaiswal > +919026283397 > B.TECH IT > IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.