what do you mean by subtree? A node with its all descendents? Or possibly a node with for example its left subtree? Anyway that's a simple task. Recursively compute for childs then check wether it worths to have L+R+root.value or simply just R or L. If you mean subtree to be a node with possibly one of its childs, then check also R+root.value and L+root.value.
-----Original Message----- From: algogeeks@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Debajit Adhikary Sent: Tuesday, January 29, 2008 1:18 PM To: Algorithm Geeks Subject: [algogeeks] Re: Finding the subtree with the largest weight Well, we need to return the *node* which is at the root of the subtree with the largest weight. On Jan 29, 4:40 am, "Nima Aghdaie" <[EMAIL PROTECTED]> wrote: > int maxw(node root) > { > if(root == null) return (0); > int L = maxw(root.lchild); > int R = maxw(root.rchild); > return max( (max(R,L,R+L)+root.value), R, L, root.value ); > > } > -----Original Message----- > From: algogeeks@googlegroups.com [mailto:[EMAIL PROTECTED] On > > Behalf Of Debajit Adhikary > Sent: Tuesday, January 29, 2008 12:40 PM > To: Algorithm Geeks > Subject: [algogeeks] Re: Finding the subtree with the largest weight > > > On Jan 29, 2008 3:07 PM, Debajit Adhikary <[EMAIL PROTECTED]> wrote: > > > > Lets say I have a weighted tree (with positive, zero and negative > > > weights for each node). > > > How could I best find the subtree having the maximum weight? > > On Jan 29, 3:55 am, "Yingjie Xu" <[EMAIL PROTECTED]> wrote: > > A rooted tree or a general tree? > > It is a rooted weighted tree, where each node is assigned a weight > which can be positive, zero or negative. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---