Data Structures & AlgorithmsHard

Why does Floyd's method for finding a duplicate in an array of n+1 values in 1..n view the array as a linked structure?

  1. A. Each index points to the next index a[i], so a repeated value creates two paths into the same node, which forms a cycle whose entrance is the duplicate.
  2. B. The array is physically a linked list in memory.
  3. C. The values are sorted, so the structure is a tree.
  4. D. Each value points to its own index, so there is no cycle.

Correct answer: A. Each index points to the next index a[i], so a repeated value creates two paths into the same node, which forms a cycle whose entrance is the duplicate.

Following i → a[i] from the start must eventually enter a cycle because two indices share a target; the cycle's entry point is the duplicate value. Floyd's two pointers locate it in linear time with constant space.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic