ProgrammingHardGATE CS · Campus placements

For the array {4, 1, 3}, how many index pairs i < j have a[i] > a[j]? These pairs are called inversions.

  1. A. 1
  2. B. 2
  3. C. 3
  4. D. 0

Correct answer: B. 2

The inversions are (4,1) and (4,3), so there are 2. Merge sort counts inversions in O(n log n) by counting during each merge.

More C Programming questions

Exams that ask this topic