[algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-07-01 Thread bittu
@Dave I Think So We Can Construct In the same we construct singly linked list ton BST . Shashank -- 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,

Re: [algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-07-01 Thread hary rathor
struct bst * BSTsearch(struct bst ** MAIN_ROOT,key) { if ( MAIN_ROOT==NULL ) return NULL; if(MAIN_ROOT-data==key) return MAIN_ROOT;

Re: [algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-07-01 Thread sunny agrawal
@Muthuraj DLL to BST back is not possible In the first step while converting to DLLwe will create a sorted DLL using inorder walk of the tree so DLL will represent the inorder sequence of nodes of BST and we know there can be many BST's for the given inorder so we can not construct the same

Re: [algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-29 Thread Swathi
Anyone able to code the dave's proposal to do inoder and reverse of inorder at the same time? On Mon, Jun 27, 2011 at 11:32 PM, Swathi chukka.swa...@gmail.com wrote: Dave, I am unable to write code for this so i am asking your help. Thanks, Swathi On Mon, Jun 27, 2011 at 11:28 PM, Dave

[algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-29 Thread Dave
@Bittu: When you are finishedm can you change the DLL back into the original BST? Dave On Jun 29, 5:54 pm, bittu shashank7andr...@gmail.com wrote: Algorithm: 1.Convert BST into sorted DLL which Will Take O(N) Time(Check previous Posts Already Coded) you can see here cslibrary.stanford.edu/109

[algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread Dave
@Nishant: No need to store the data in an array. Do two inorder traversals simultaneously. Let u and v be the current nodes of the two traversals, respectively. If u + v x, then advance the v traversal. If u + v x, advance the u traversal. Dave On Jun 27, 3:40 am, Nishant Mittal

Re: [algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread sunny agrawal
@Dave i think your solution won't work consider inorder traversal of a BST is 1 6 7 8 15 and x = 14 initially both u,v (1,1) according to u your algorithm will proceed like (1,1) - (1,6) - (1,7) - (1,8) - (1,15) - (6,15) - (15,15) and clearly in second step of your solution if (u+v)

[algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread juver++
It doesn't work. In your idea values of nodes represented by u and v always increased, cause you are doing inorder traversal. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

[algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread Dave
@Sunny. Mea culpa. You are correct. Revised (and correct) algorithm. Do two inorder traversals, one in the usual (descend to the left before descendung to the right) direction and the other in the reversed(descend to the right before descending to the left) direction. Let u and r be the current

[algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread juver++
Yes, now it is fine enough :) -- 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/-/8z1hcl2hQskJ. To post to this group, send email to algogeeks@googlegroups.com.

Re: [algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread Swathi
Dave, Can you provide the psuedo code for this.. Thanks, Swathi On Mon, Jun 27, 2011 at 7:30 PM, Dave dave_and_da...@juno.com wrote: @Sunny. Mea culpa. You are correct. Revised (and correct) algorithm. Do two inorder traversals, one in the usual (descend to the left before descendung to the

Re: [algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread Bharath Soma
@ankit, sorry i was mistaken its O(nlogn) for searching the two elements... On Mon, Jun 27, 2011 at 8:04 PM, Swathi chukka.swa...@gmail.com wrote: Dave, Can you provide the psuedo code for this.. Thanks, Swathi On Mon, Jun 27, 2011 at 7:30 PM, Dave dave_and_da...@juno.com wrote:

Re: [algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread varun pahwa
suppose k is the sum to be found. @vaibhav: yes it will stop when crossing is there means (j must be greater than i).initially sum = a[i] + a[j] (where i = 0 n j = n- 1) n we will increase i when sum is less than k and decrease j when sum k.stop if sum == k. and if no i , j found till j i. then

Re: [algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread vaibhav agarwal
@varun: Thanks... On Mon, Jun 27, 2011 at 9:18 PM, varun pahwa varunpahwa2...@gmail.comwrote: suppose k is the sum to be found. @vaibhav: yes it will stop when crossing is there means (j must be greater than i).initially sum = a[i] + a[j] (where i = 0 n j = n- 1) n we will increase i when

[algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread Dave
@Swathi: No. I think the high level description should be adequate for you to write your own code or pseudocode, albeit recognizing that you may have to look up how to do an inorder traversal using a stack instead of recursion. Dave On Jun 27, 9:34 am, Swathi chukka.swa...@gmail.com wrote:

Re: [algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread Swathi
Dave, I am unable to write code for this so i am asking your help. Thanks, Swathi On Mon, Jun 27, 2011 at 11:28 PM, Dave dave_and_da...@juno.com wrote: @Swathi: No. I think the high level description should be adequate for you to write your own code or pseudocode, albeit recognizing that you

Re: [algogeeks] Re: given a bst and a value x.find pair of nodes in the tree that sum upto x

2011-06-27 Thread Piyush Sinha
how about converting the BST into a doubly linked list...but this will definitely modify the BST.. On Mon, Jun 27, 2011 at 11:32 PM, Swathi chukka.swa...@gmail.com wrote: Dave, I am unable to write code for this so i am asking your help. Thanks, Swathi On Mon, Jun 27, 2011 at 11:28 PM,