[algogeeks] Re: print all paths which sum up to a value.

2011-08-24 Thread Dumanshu
Any help regarding the preprocessing required for O(1) operation for LCA??? I read the wiki's article involving eulers traversal.. but its nt clear. On Aug 24, 1:12 am, DK wrote: > Hmm.. Interesting question. > > *Here's a solution:* > > There are n elements in the tree and therefore n^2 paths in

[algogeeks] Re: print all paths which sum up to a value.

2011-08-23 Thread DK
Hmm.. Interesting question. *Here's a solution:* There are n elements in the tree and therefore n^2 paths in the tree (duplicate endpoints allowed and 2 endpoints correspond to exactly 1 simple path in the tree). 1. For each node in the BST, store the sum of node values on the path to the root

Re: [algogeeks] Re: print all paths which sum up to a value.

2011-08-22 Thread Anil Arya
I'm very sry dude..It was not me as any intelligent person can understand. On Tue, Aug 23, 2011 at 3:49 AM, Anil Arya wrote: > fuck > > > On Mon, Aug 22, 2011 at 12:52 AM, Dhriti Khanna wrote: > >> void search_path( root , int i ) >> { >>static char str[100]; >>if(root == nul

Re: [algogeeks] Re: print all paths which sum up to a value.

2011-08-22 Thread Anil Arya
fuck On Mon, Aug 22, 2011 at 12:52 AM, Dhriti Khanna wrote: > void search_path( root , int i ) > { >static char str[100]; >if(root == null) > return; > >if( i == 0 ) > str[i] = root->data; > >else str[i] = str[i-1] + root->data; // Maintaining t

Re: [algogeeks] Re: print all paths which sum up to a value.

2011-08-21 Thread Dhriti Khanna
void search_path( root , int i ) { static char str[100]; if(root == null) return; if( i == 0 ) str[i] = root->data; else str[i] = str[i-1] + root->data; // Maintaining the cumulative sum of all the sums till now. if ( str[i] == value )

Re: [algogeeks] Re: print all paths which sum up to a value.

2011-08-19 Thread MAC
10 20 30 4 66 7 now how do u make 60 => 20 +10+30 how do u make 36 :: 10 + 20 +6 30+6 On Fri, Aug 19, 2011 at 8:37 PM, Arun Vishwanathan wrote: > @mac: just to clear my understanding, u need to print paths that sum up to > a Val

Re: [algogeeks] Re: print all paths which sum up to a value.

2011-08-19 Thread Arun Vishwanathan
@mac: just to clear my understanding, u need to print paths that sum up to a Value which means the value of the nodes in a path is added right to see if it satisfies this Value? does the value at each node have any relevance as such? I mean can it be any value at any node or does value at a node sa

Re: [algogeeks] Re: print all paths which sum up to a value.

2011-08-19 Thread anshu mishra
start from leaves.(leaves have possible sum only its value) go up step by step save all the possible sums on that node. for example if left node has possible sums( 4, 6, 7 ,13) and right node has possible sums (3, 5, 9); and node itself value has 5 than this node all possible sums will be (8, 10,

[algogeeks] Re: print all paths which sum up to a value.

2011-08-19 Thread MAC
any suggestion frds ?? my thinking is eitther a) root + left formsa path b) oot +right form a path c) left +root +right form a path d) path only in left e) path only in right this thought process seems to be worng to me as its highly expensive and i am myself not convinced of what to do next . An