Data Structures & AlgorithmsModerate

How many ordered pairs (i, j) with i ≠ j in 3 1 4 1 5 satisfy A[i] > A[j]?

  1. A. 3
  2. B. 9
  3. C. 11
  4. D. 10

Correct answer: B. 9

Count each ordered pair separately: a pair with unequal values contributes exactly once in the order that puts the larger first. Counting unordered pairs, unequal pairs, or using ≥ (which admits equal values) gives other totals.

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

Exams that ask this topic