Update on 2nd line 2. if( ptr2=ptr1->next->next.......(5 or 10 times) ) goto 3. else make linear search till NULL encounter and exit with the solution
On Mon, Jul 18, 2011 at 7:41 PM, sagar pareek <[email protected]> wrote: > i have one approach :- > > first compare root->data and k > if k is very much greater than root->data then set next=5or10 ur choice > > else set next 2or3 ur choice > take two pointers ptr1 and ptr2 > > now lets take k is much greater than root->data > then > 1. set ptr1=root //initially > 2. if( ptr2=ptr1->next->next.......(5 or 10 times) ) else make linear > search till NULL encounter > 3. if ptr2->data==k return its position > 4. else if (ptr2->data>k) set ptr1=ptr2 goto 2 > 5. else traverse the ptr1 upto ptr2, if found return its position else > return fail > > if anyone has more efficient solution then pls tell :) > > On Mon, Jul 18, 2011 at 6:53 PM, Dumanshu <[email protected]> wrote: > >> You have a sorted linked list of integers of some length you don't >> know and it keeps on increasing. You are given a number k. Print the >> position of the number k. >> Basically, you have to search for number k in the ever growing sorted >> list and print its position. >> >> Please write the complexity of whatever solution you propose. >> >> -- >> 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 > > -- **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.
