[Solved] Which of the following form inversion in the array arr = {1,5,4,2}?

Which of the following form inversion in the array arr = {1,5,4,2}?

a) (5,4), (5,2)
b) (5,4), (5,2), (4,2)
c) (1,5), (1,4), (1,2)
d) (1,5)

Answer: b
Explanation: The necessary condition for an inversion is arr[i]>arr[j] and i<j. So there are 3 inversions in the array. These are (5,4), (5,2), (4,2).

Comments