Counting Inversions

Definition (Inversion)

Ranking 1 = and Ranking 2 = . Elements and of are inverted if but

Similarity Metric: The fewer inversions between two rankings, the more similar they are.

Goal: Count the number of inversions

Divide: Separate list into two halved and Conquer: Recursively count inversions in each list Combine: Count inversions with and

  • Sort and
  • For each element , binary search in to find how many elements in are greater than