GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A singly linked list has 17 nodes numbered 0 to 16 from the head; node 16 points back to node 7 (so the tail of length 7 leads into a cycle of length 10). Slow moves 1 step and fast moves 2 steps per round, both starting at node 0. After how many rounds do they first meet, and at which node?

  1. A. 8 rounds at node 10
  2. B. 10 rounds at node 10
  3. C. 10 rounds at node 7
  4. D. 11 rounds at node 11

Correct answer: B. 10 rounds at node 10

They meet after t rounds where The fast pointer gains 1 node per round, so they meet when the gap is a multiple of the cycle length 10 and both are inside the cycle; the first such round is t = 10, where slow stands at node 10 (not at the entry node 7).

More Programming and Data Structures (GATE) questions

Exams that ask this topic