On Wed, Aug 18, 2010 at 5:12 AM, jayapriya surendran <priya7...@gmail.com>wrote:
> hi..i wanna know what is brent's algorithm n whether it can be used to > detect loops in linked list.If yes..is it better than Floyd's cycle > finding algo? > Brent's algorithm is also called Tortoise and Rabbit algorithm.It has been proved by brent's that it is 36% faster than floyd's loop detection algorithm. bool cycle_check(LL list){ rabbit=list.top; tortoise=list.top; step_val=0; step_limit=2; while(1){ if(rabbit->next==NULL) return 0; rabbit=rabbit->next; step_val+=1; if(rabbit==tortoise) return 1; if(step_val==step_limit){ step_val=0; step_limit*=2; tortoise=rabbit; } }//while ends }//func ends. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Thanks & Regards Nikhil Agarwal Senior Undergraduate Computer Science & Engineering, National Institute Of Technology, Durgapur,India http://tech-nikk.blogspot.com http://beta.freshersworld.com/communities/nitd -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@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.