Regarding Floyd's cycle-finding algorithm

  • Context: Undergrad 
  • Thread starter Thread starter cyberfrenzy
  • Start date Start date
  • Tags Tags
    Algorithm
Click For Summary
SUMMARY

Floyd's cycle-finding algorithm, also known as the Tortoise and Hare algorithm, effectively detects cycles in a sequence by utilizing two pointers moving at different speeds. The tortoise moves one step at a time while the hare moves two steps, ensuring they will eventually meet if a cycle exists. The mathematical proof of their meeting point involves analyzing their positions after k steps, particularly when starting M places apart on a cycle of size N. This discussion emphasizes the importance of understanding the relationship between the step sizes and the cycle's structure.

PREREQUISITES
  • Understanding of Floyd's cycle-finding algorithm
  • Basic knowledge of modular arithmetic
  • Familiarity with cycle detection in data structures
  • Concept of pointers in algorithm design
NEXT STEPS
  • Study the mathematical proof of Floyd's cycle-finding algorithm
  • Explore modular arithmetic applications in cycle detection
  • Learn about other cycle detection algorithms, such as Brent's algorithm
  • Investigate the performance implications of different pointer strategies
USEFUL FOR

Computer scientists, algorithm enthusiasts, and software developers interested in cycle detection techniques and their mathematical foundations.

cyberfrenzy
Messages
3
Reaction score
0
Well I understand what is happening - the tortoise moving 1 step, and the hare moving 2 steps and finally coinciding at a point. But I want a mathematical proof of this - ie; when you have 2 counters moving in a cycle, one going 1 step, the other 2 steps, then they finally meet at a point.
 
Physics news on Phys.org
Suppose that they start M places apart (suitably oriented) on a cycle of size N. How many places apart are they after k steps?
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
Replies
7
Views
3K
  • · Replies 65 ·
3
Replies
65
Views
9K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K