Re: [algogeeks] Amazon Interview Q
if we take 2 pointers initialized with the start node with one moving in forward direction and other in backward direction and execute until both point to same node .it cud be workin faster i suppose... On Thu, Aug 18, 2011 at 1:21 AM, Piyush Sinha ecstasy.piy...@gmail.comwrote: We all knw hw to find a loop in a singly linked list (Using hare and tortoise method)..what if the linked list is a doubly linked list?can we do it smthn better than hare n tortoise method using the advantage of the doubly linked list? -- *Piyush Sinha* *IIIT, Allahabad* *+91-7483122727* * https://www.facebook.com/profile.php?id=10655377926 NEVER SAY NEVER * -- 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. -- 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.
Re: [algogeeks] Amazon Interview Q
But it is not circular doubly linked list.,..so u could not traverse in backward dirction from HEAD node.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/0KIdBDCY49MJ. 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.
Re: [algogeeks] Amazon Interview Q
WHERE will the back pointer of intersecting node will point? On Wed, Aug 17, 2011 at 3:47 PM, Brijesh Upadhyay brijeshupadhyay...@gmail.com wrote: But it is not circular doubly linked list.,..so u could not traverse in backward dirction from HEAD node.. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/0KIdBDCY49MJ. 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. -- *UTKARSH SRIVASTAV CSE-3 B-Tech 3rd Year @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.
Re: [algogeeks] Amazon Interview Q
At the node from where the loop just started.. anyway we could not use that logic , coz it isnt circular linked list! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/sr4w-kPmnEsJ. 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.
Re: [algogeeks] Amazon Interview Q
ys...i guess i misinterpreted..the question.. ma fault... On Thu, Aug 18, 2011 at 4:27 AM, Brijesh Upadhyay brijeshupadhyay...@gmail.com wrote: At the node from where the loop just started.. anyway we could not use that logic , coz it isnt circular linked list! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/sr4w-kPmnEsJ. 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. -- 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.
Re: [algogeeks] Amazon Interview Q
I have come up with this: - Use only one pointer, NODE *cur - initialize cur to headref - The main loop: while (cur) { if(cur-next-prev != cur) break; cur=cur-next; } return cur; ^^ I think the code is self explanatory. It just uses the fact that at loop, the prev of next to current won't be current. e.g. A-B-C-D-E-F-C Though F is pointing to C, C won't be pointing back to F as the prev of C is pointing to B. Complexity: O(n) On 18 August 2011 04:45, payal gupta gpt.pa...@gmail.com wrote: ys...i guess i misinterpreted..the question.. ma fault... On Thu, Aug 18, 2011 at 4:27 AM, Brijesh Upadhyay brijeshupadhyay...@gmail.com wrote: At the node from where the loop just started.. anyway we could not use that logic , coz it isnt circular linked list! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/sr4w-kPmnEsJ. 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. -- 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. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- 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.
Re: [algogeeks] Amazon Interview Q
A slight change in above code: make it while(cur cur-next) ^^ other wise the code will crash at last element in a prefect list, with no loop. On 18 August 2011 07:36, Dipankar Patro dip10c...@gmail.com wrote: I have come up with this: - Use only one pointer, NODE *cur - initialize cur to headref - The main loop: while (cur) { if(cur-next-prev != cur) break; cur=cur-next; } return cur; ^^ I think the code is self explanatory. It just uses the fact that at loop, the prev of next to current won't be current. e.g. A-B-C-D-E-F-C Though F is pointing to C, C won't be pointing back to F as the prev of C is pointing to B. Complexity: O(n) On 18 August 2011 04:45, payal gupta gpt.pa...@gmail.com wrote: ys...i guess i misinterpreted..the question.. ma fault... On Thu, Aug 18, 2011 at 4:27 AM, Brijesh Upadhyay brijeshupadhyay...@gmail.com wrote: At the node from where the loop just started.. anyway we could not use that logic , coz it isnt circular linked list! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/sr4w-kPmnEsJ. 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. -- 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. -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- ___ Please do not print this e-mail until urgent requirement. Go Green!! Save Papers = Save Trees -- 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.