Data Structures & AlgorithmsVery hardGATE CSE

How many inversions (pairs i < j with a[i] > a[j]) does [8, 4, 2, 1, 7, 3, 6, 5] have?

  1. A. 13
  2. B. 17
  3. C. 19
  4. D. 15

Correct answer: D. 15

Per element, the smaller items to its right are 7, 3, 1, 0, 3, 0, 1, 0, which total 15.

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

Exams that ask this topic