Data Structures & AlgorithmsVery hard

Which statement about inversion counting with repeated values is correct?

  1. A. Equal values form inversions and should be counted with a[i] ≥ a[j].
  2. B. Duplicates are removed before counting, so they cannot change the answer.
  3. C. Inversions exist only between adjacent positions.
  4. D. Equal values are not inversions, so the test must be strictly a[i] > a[j] for i < j.

Correct answer: D. Equal values are not inversions, so the test must be strictly a[i] > a[j] for i < j.

An inversion needs a strictly larger value before a smaller one; equal values are in order and never form an inversion. Counting with ≥ or removing duplicates changes the number and is a common error.

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

Exams that ask this topic