Re: [algogeeks] Re: max sum b/w 2 leaf nodes in a binary tree
@navin it is not necessary that path b/w two leaves always pass thru root. On Wed, Aug 29, 2012 at 1:15 AM, Navin Gupta navin.nit...@gmail.com wrote: I think the path between two leaves always passes thru root. Now we can keep track of root-to-leaf path whose sum is max and secondMax among all sums. Now between this two leaves path, root is repeated. Hence actual sum is maxsum + secondMaxSum - root-val; This can be done by iterative inorder traversal of tehe tree T[n] - o[n] Space - o[n] -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/5Okg0EjlIAkJ. 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. -- 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.
Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree
@ravi yep, you're right. But method is similar to finding diameter as given on geeksforgeeks as atul suggested . Thanks. On Mon, Aug 27, 2012 at 11:23 PM, Ravi Maggon maggonr...@gmail.com wrote: @atul: I think he is asking for max. sum of elements between 2 leaf nodes and not the max distance between two nodes. On Sun, Aug 26, 2012 at 6:12 PM, atul anand atul.87fri...@gmail.comwrote: its the diameter of tree. you can find implementation on geeksforgeeks On 8/25/12, kunal rustgi rustogi.ku...@gmail.com wrote: Hi, Can anyone suggest the best approach for finding max sum b/w 2 leaf nodes in a binary tree ( not BST ) ? -- 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. -- 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. -- *Regards *Ravi Maggon Member Technical - IT/Front Office D.E. Shaw Co. -- 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. -- 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.
Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree
int maxLtoLSum(NODE *root,int *sum) { int ls=0,rs=0,lsum=0,rsum=0; if(root==NULL) { *sum=0; return 0; } lsum= maxLtoLSum (root-left,ls); rsum= maxLtoLSum (root-right,rs); *sum=max(ls,rs) + root-data; return max(ls + rs + root-data, max(lsum,rsum)); } On Tue, Aug 28, 2012 at 4:02 PM, vaibhav shukla vaibhav200...@gmail.comwrote: I guess it might be finding maximum sum path for left subtree + max sum path for right subtree + root-data As in case of finding the diameter which say height(root-left)+height(root-right)+1 Please correct me! On Mon, Aug 27, 2012 at 11:46 PM, kunal rustgi rustogi.ku...@gmail.comwrote: @ravi yep, you're right. But method is similar to finding diameter as given on geeksforgeeks as atul suggested . Thanks. On Mon, Aug 27, 2012 at 11:23 PM, Ravi Maggon maggonr...@gmail.comwrote: @atul: I think he is asking for max. sum of elements between 2 leaf nodes and not the max distance between two nodes. On Sun, Aug 26, 2012 at 6:12 PM, atul anand atul.87fri...@gmail.comwrote: its the diameter of tree. you can find implementation on geeksforgeeks On 8/25/12, kunal rustgi rustogi.ku...@gmail.com wrote: Hi, Can anyone suggest the best approach for finding max sum b/w 2 leaf nodes in a binary tree ( not BST ) ? -- 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. -- 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. -- *Regards *Ravi Maggon Member Technical - IT/Front Office D.E. Shaw Co. -- 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. -- 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. -- best wishes!! Vaibhav -- 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. -- 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.
[algogeeks] max sum b/w 2 leaf nodes in a binary tree
Hi, Can anyone suggest the best approach for finding max sum b/w 2 leaf nodes in a binary tree ( not BST ) ? -- 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.