Explanation

- Floyd’s Cycle Detection Algorithm, also known as **Tortoise and Hare**, is used to detect if there is a cycle in a linked list. It uses two pointers moving at different speeds.

-

  • Steps:
    • Initialize two pointers, slow and fast, both starting at the head of the list.
    • Move slow one step and fast two steps in each iteration.
    • If there is a cycle, slow and fast will eventually meet.
    • If fast or fast.next becomes None, there is no cycle.
  • Time Complexity

    • O(n), where n is the number of nodes in the linked list.