The Tortoise and Hare algorithm, also known as Floyd's Cycle-Finding Algorithm, is used to detect loops in a linked list. It uses two pointers: a slow pointer (tortoise) that moves one step at a time, and a fast pointer (hare) that moves two steps. If there's a cycle, the hare will eventually catch up to the tortoise.
Step 1: Initialize the tortoise (slow) and hare (fast) pointers at the start of the linked list.
Step 2: Move the tortoise one step forward.
Step 3: Move the hare two steps forward.
Step 4: Continue this pattern: tortoise moves one step, hare moves two steps.
Step 5: If there's a cycle, the hare will eventually catch up to the tortoise.
Step 6: When the hare and tortoise meet, we've confirmed there's a cycle in the linked list!