GATE Computer ScienceModerateGATE CSE · NIELIT

How many inversions (pairs i<j with A[i]>A[j]) does the array [7, 3, 9, 1, 5, 8, 2] contain?

  1. A. 12
  2. B. 10
  3. C. 14
  4. D. 16

Correct answer: A. 12

Counting later smaller elements for each position gives 4 + 2 + 4 + 0 + 1 + 1 + 0 = 12.

More Algorithms questions

Exams that ask this topic