The number of inversions is a common measure of how sorted an array is.
A pair of elements (pi,pj) in a permutation p is called an inversion in a permutation if i<j and pi >pj . For example, in the permutation (3,1,2,5,4) are 3 inversions (3,1) , (3,2) and (5,4) .
The sorted array received 0 inverse, and the reverse sorted array received n * (n-1) / 2.
Zimbabao
source share