Data Structures & AlgorithmsVery hard

Why does a circular window of length 3 require index arithmetic modulo n?

  1. A. Because circular arrays cannot be indexed at all.
  2. B. So that the sum is taken modulo n.
  3. C. To make the array shorter.
  4. D. So that windows can wrap past the last index and continue from the first, covering every circular block.

Correct answer: D. So that windows can wrap past the last index and continue from the first, covering every circular block.

A circular block may start near the end and continue at the beginning, so each start index i uses positions (i+t) mod n. Without the modulo, the wrap-around windows would be missed.

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

Exams that ask this topic