Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread Sairam
So, how do you do that sir? Basically , we should identify all the paths between those two nodes and keep track of maximum of sums. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread kunal rustgi
@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

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread vaibhav shukla
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

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread pankajsingh
Hope This will Work.. int Recursion(node *root) { if(root-left==Nullroot-right==Null) { return root-data; } int a=0,b=0; a=recursion(root-left); b=recursion(root-right); if(a+b+root-datamax) max=a+b+root-data; return max(a,b)+root-data; } -- You received this message because you are subscribed

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread pankajsingh
@vaibhav-yup :-) -- 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

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-28 Thread kunal rustgi
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,

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-27 Thread Ravi Maggon
@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.com wrote: its the diameter of tree. you can find implementation on geeksforgeeks On 8/25/12, kunal rustgi

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-27 Thread Dave
@Ravi: That is also my understanding, so the solution involves traversing the tree and keeping track of the values of the two largest leaf nodes. Dave On Monday, August 27, 2012 12:53:05 PM UTC-5, Ravi Maggon wrote: @atul I think he is asking for max. sum of elements between 2 leaf nodes

[algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-26 Thread kunal rustgi
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

Re: [algogeeks] max sum b/w 2 leaf nodes in a binary tree

2012-08-26 Thread atul anand
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

Re: [algogeeks] Max sum circular array

2012-07-24 Thread hary rathor
we can be use logical window and slide through the array in circular manner. apply kandane's algo on logical window. -- 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

Re: [algogeeks] Max sum circular array

2012-07-10 Thread adarsh kumar
This is similar to maximum sum contiguous subarray problem. Consider the circular array as a normal array, except that once you reach the end of the array, if the sum found upto that element(using Kandane's algo, refer Wiki) is negative, then try including elements from the beginning of the

[algogeeks] Max sum circular array

2012-07-09 Thread deepikaanand
What is best approach to find max sum in a circular array... -- 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

Re: [algogeeks] max sum in submatrix

2011-08-30 Thread sukran dhawan
kadane 's algo ? On Tue, Aug 30, 2011 at 1:19 AM, tech coder techcoderonw...@gmail.comwrote: given a matrix with +ve and -ve numbers find the sub matrix with max sum -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] max sum in submatrix

2011-08-30 Thread tech coder
can u elaborate On Tue, Aug 30, 2011 at 11:13 AM, sukran dhawan sukrandha...@gmail.comwrote: kadane 's algo ? On Tue, Aug 30, 2011 at 1:19 AM, tech coder techcoderonw...@gmail.comwrote: given a matrix with +ve and -ve numbers find the sub matrix with max sum -- You received this

[algogeeks] max sum in submatrix

2011-08-29 Thread tech coder
given a matrix with +ve and -ve numbers find the sub matrix with max sum -- 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] max sum

2010-06-11 Thread divya
Given an array all of whose elements are positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent in the array. Eg. i) 3 2 7 10 should return 13 (sum of 3 and 10) ii) 3 2 5 10 7 should return 15 (sum of 3, 5 and 7) -- You

Re: [algogeeks] max sum

2010-06-11 Thread Jitendra Kushwaha
this can done by dyanamic programming At every point keep the maximum sum including the current element and excluding the current element At last the maimum will be max of both the maximum pseudo code : max1 = max2 = 0 for i in 1 to n temp = max2 max1 = MAX(max1, max2+array[i])

Re: [algogeeks] max sum

2010-06-11 Thread Dheeraj Jain
See http://geeksforgeeks.org/?p=3133 for solution. On Fri, Jun 11, 2010 at 8:41 AM, divya sweetdivya@gmail.com wrote: Given an array all of whose elements are positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent