@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
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
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
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 ||
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
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
@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
@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
@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
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.
--
@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,
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
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.
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:
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
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
16 matches
Mail list logo