can someone explain in general Don's code? On Wed, Aug 10, 2011 at 8:54 AM, Venkat <venkataharishan...@gmail.com>wrote:
> Don solution is perfect. > i double checked it...... > > On Aug 9, 9:01 pm, Don <dondod...@gmail.com> wrote: > > tree closestSharedAncestor(tree root, tree node1, tree node2, int > > &result) > > { > > tree returnValue = 0; > > > > if (root) > > { > > if (root == node1) result += 1; > > if (root == node2) result += 2; > > int sum = 0; > > tree returnLeft = closestSharedAncestor(root->left, node1, node2, > > sum); > > if (returnLeft) returnValuet = returnLeft; > > else > > { > > tree returnRight = closestSharedAncestor(root->right, node1, > > node2, sum); > > if (returnRight) returnValue = returnRight; > > else if (sum == 3) returnValue = root; > > } > > result += sum; > > } > > return returnValue; > > > > } > > > > On Aug 9, 9:56 am, Raman <raman.u...@gmail.com> wrote: > > > > > > > > > Can anyone give me the recursive algo to find closest ancestor of two > nodes > > > in a tree(not a BST).- Hide quoted text - > > > > - Show quoted text - > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@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. > > -- "People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily." -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@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.