6.20 Inversion Counting
6.20 Inversion Counting An inversion is a pair of positions that appears in the opposite order from the final sorted order. Inversion counting measures how far an array is from being sorted. It is useful for ranking distance, sorting analysis, permutation comparison, and adaptive algorithm design. Problem You have an array A[0..n-1] . You want to count the number of pairs (i, j) such that: i < j and A[i]...