Data Structures & AlgorithmsHard

To count ordered pairs (i, j), i ≠ j, with A[i] + A[j] ≡ 0 (mod 5), which correction turns an unordered-pair count into the ordered one?

  1. A. Add the number of elements, since each element pairs with itself.
  2. B. Square the unordered count.
  3. C. Halve the unordered count.
  4. D. Double the unordered count, since each unordered pair gives two ordered pairs when i ≠ j.

Correct answer: D. Double the unordered count, since each unordered pair gives two ordered pairs when i ≠ j.

For i ≠ j, each unordered pair {i, j} yields exactly two ordered pairs, so the ordered count is twice the unordered count. Self-pairs are excluded by the statement.

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

Exams that ask this topic