Written by
Bernardo

on

on

# floyd's tortoise and hare algorithm

TIL about Floyd’s Tortoise and Hare algorithm.

This algorithm is used to detect whether there is a cycle in a list, and given that a cycle exists its starting point and the length of the cycle.

The algorithm can also be used to prove the existence of duplicate numbers in a list.

The time complexity of this algorithm is linear: `O(n)`

.

The space complexity of this algorithm is constant: `O(1)`

.