OK On Sun, Jul 17, 2011 at 2:59 PM, saurabh singh <[email protected]> wrote:
> 9 1 is analogous to 1 9...And the question requires only two nodes,it does > not says about all such pairs. > > > On Sun, Jul 17, 2011 at 2:52 PM, sagar pareek <[email protected]>wrote: > >> OK... >> suppose our tree is >> >> 5 >> / \ >> 4 6 >> / \ >> 3 7 >> / \ >> 2 8 >> / \ >> 1 9 >> >> now k=10; >> so will it return all the pairs like 1,9 2,8 . . ..5,5. . . .. .8,2 9,1 >> ?? >> >> On Sun, Jul 17, 2011 at 7:00 AM, saurabh singh <[email protected]>wrote: >> >>> @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 [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]. >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> >> >> -- >> **Regards >> SAGAR PAREEK >> COMPUTER SCIENCE AND ENGINEERING >> NIT ALLAHABAD >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > Saurabh Singh > B.Tech (Computer Science) > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- **Regards SAGAR PAREEK COMPUTER SCIENCE AND ENGINEERING NIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
