[algogeeks] Re: BST Problem

2010-08-25 Thread Giri
@arvind: had i knwn would hv posted it On Aug 23, 8:59 am, R.ARAVINDH aravindhr...@gmail.com wrote: @giri: can u post d correct answer?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to

Re: [algogeeks] Re: BST Problem

2010-08-23 Thread Raj N
Perform inorder traversal and store in an array. low = 0, high = size-1 while(low=high) { if ( a[low] + a[high] sum) low++; else if (a[low] + a[high] sum) high--; else return a[high] and [low] } On Mon, Aug 23, 2010 at 9:29 AM, R.ARAVINDH aravindhr...@gmail.com wrote: @giri: can

Re: [algogeeks] Re: BST Problem

2010-08-23 Thread TurksHead Education
I am not sure if I am repeating the answer: The problem will reduce to find the pair of elements which will sum up to a particular number. Then read the below article, http://www.rawkam.com/?p=345 On Mon, Aug 23, 2010 at 9:29 AM, R.ARAVINDH aravindhr...@gmail.com wrote: @giri: can u post

[algogeeks] Re: BST Problem

2010-08-22 Thread R.ARAVINDH
can v do like this??? findnodes(root,sum) { if(root==abs(sum-root-data)) print (the data is root-data, sum-(root-data)); else if(rootabs(sum-root-data)) findnodes(root-right,sum-root-data) else if(rootabs(sum-root-data)) findnodes(root-left,sum-root-data) else if(root-left==NULL ||

[algogeeks] Re: BST Problem

2010-08-22 Thread R.ARAVINDH
for the above post i have assumed that the two nodes whose sum is k is present in the BST... so correct me if m wrong -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To

[algogeeks] Re: BST Problem

2010-08-22 Thread Giri
frnd check ur code.. t contains much errors.. consider the following eg.: k=5;3 1 4 2 5 On Aug 22, 2:30 pm, R.ARAVINDH aravindhr...@gmail.com wrote: can v do like  this??? findnodes(root,sum) { if(root==abs(sum-root-data)) print (the data

[algogeeks] Re: BST Problem

2010-08-22 Thread R.ARAVINDH
@giri: thnx frnd...sorry ppl . ignore my post :( -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: BST Problem

2010-08-22 Thread R.ARAVINDH
@giri: can u post d correct answer?? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For

[algogeeks] Re: BST Problem

2010-08-10 Thread Avik Mitra
@Sekin. Sort the elements (increasing order). This has already been mentioned. So, answer will be 1, 100. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from

Re: [algogeeks] Re: BST Problem

2010-08-10 Thread Seçkin Can Şahin
Avik, yes the answer is obvious but your code doesn't find that. that 2 pointer approach is the correct one. On Tue, Aug 10, 2010 at 12:07 AM, Avik Mitra tutai...@gmail.com wrote: @Sekin. Sort the elements (increasing order). This has already been mentioned. So, answer will be 1, 100. --

[algogeeks] Re: BST Problem

2010-08-10 Thread Avik Mitra
@Sekin Yes that's true.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options,

Re: [algogeeks] Re: BST Problem

2010-08-06 Thread Seçkin Can Şahin
as a hint, convert the BST to a sorted array and take two pointers one pointing to the first number and the other pointing to the last. Then, move pointers appropriately to find the two numbers summing up to k. complexity: O(n) 2010/8/5 Seçkin Can Şahin seckincansa...@gmail.com what about the

Re: [algogeeks] Re: BST Problem

2010-08-06 Thread Manjunath Manohar
the solution elegant..but is there any on the fly method by just exploiting the BST propertyby using left and right pointers -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this group, send email to algoge...@googlegroups.com.

Re: [algogeeks] Re: BST Problem

2010-08-06 Thread Chonku
Two inorders would achieve the same thing without using an array. One pointer running inorder with LDR and other pointer running inorder with RDL. Compare the sum at the two nodes and then adjust them accordingly. On Fri, Aug 6, 2010 at 2:11 PM, Manjunath Manohar manjunath.n...@gmail.comwrote:

Re: [algogeeks] Re: BST Problem

2010-08-06 Thread sharad kumar
do the inorder traversal of the bst ...this gives the sorted array.. from that use int i=0,j=length(array) while(ij) { if(array[i]+array[j]sum) --j; else if(array[i]+array[j]sum) ++i; else if((array[i]+array[j])==sum) return i,j else ++i,--j; } On Fri, Aug 6, 2010 at 3:10 PM, Chonku

Re: [algogeeks] Re: BST Problem

2010-08-06 Thread Seçkin Can Şahin
Chonku, you can do that only when you have the links to parent nodes. I couldn't come up with a way of doing what you said on a basic BST(nodes having pointers only to their 2 children) that is why I suggested using an array. It doesn't change the overall complexity but if you have an idea about