Data Structures & AlgorithmsVery hard

Which property makes the ordered-pair count of A[i] > A[j] equal to the number of unequal unordered pairs?

  1. A. Every pair of equal values also satisfies the inequality.
  2. B. For each unequal unordered pair exactly one ordering has the larger value first, so the ordered count with strict inequality equals the number of unequal unordered pairs.
  3. C. The inequality holds for both orders of every pair.
  4. D. The count is always zero.

Correct answer: B. For each unequal unordered pair exactly one ordering has the larger value first, so the ordered count with strict inequality equals the number of unequal unordered pairs.

Among the two orderings of an unequal pair only one satisfies A[i] > A[j], so the strict count equals the unequal pairs. Equal pairs satisfy neither ordering, which is why the two counts match.

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

Exams that ask this topic