@sagar This is what Dave is suggesting in a more pseudocode way:-

1->Traverse a pointer right down to the leftmost element,i.e.the
shortest,say small
2->traverse a pointer left down to the rightmost element i.e.the
largest.say
large
while(small!=large)
3->Compare their sum.If sum>k set large to its successor in reverse
inorder.(I am not sure if u meant the same but I am assuming rev inorder to
be right->node->left)
else set small to its inorder successor.
break when u get the desired k.
print :)
return
if u get out of the loop without getting the number
then such number does not exist.print :(

Amortized complexity order n.


-- 
Saurabh Singh
B.Tech (Computer Science)
5h sem
MNNIT ALLAHABAD

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to