There are more efficient ways of doing this. Refer wiki http://en.wikipedia.org/wiki/Cycle_detection#Brent.27s_algorithm
On Wed, Jul 7, 2010 at 9:16 AM, Dave <[email protected]> wrote: > @Anand. You've described one way to do it, and maybe the most > efficient way, but not the only way. > > Dave > > On Jul 6, 8:42 pm, Anand <[email protected]> wrote: > > you increment slow pointer by 1 and fast pointer by 2 to find a loop in > > Linked list. > > > > > > > > On Mon, Jul 5, 2010 at 9:02 PM, amit <[email protected]> wrote: > > > Consider the general fast and slow pointer strategy to detect loop in > > > a LL. > > > Now , Suppose we move the slowPtr 'm' nodes at a time and move the > > > fastPtr 'n' nodes at a time. What are the constraints on 'm' and 'n' > > > so that we that we are able to find whether the list is circular or > > > not? > > > > > -- > > > 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]<algogeeks%[email protected]> > <algogeeks%2bunsubscr...@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/algogeeks?hl=en.- Hide quoted text - > > > > - Show quoted text - > > -- > 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]<algogeeks%[email protected]> > . > 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 [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.
