Abstract


  • The arrangement of objects where order matters

  • Given objects, there is a total permutations. For example, given 3 objects , the total number of permutations is - , , , , ,

Permutation Inversion

  • A pair of elements that are out of order relative to each other compared to their natural order in sorted permutation
  • For example, given a permutation , the pairs and are inversions because comes before both

Indicate Chaoticness

The number of inversions in a permutation can indicate how far the permutation is from being sorted

  • We can Merge Sort to count the total inversions in a given Array. An example is given in the code editor below. The idea here is to use merge sort to count the number of inversions at each merge, leveraging the fact that at each merge, all elements in the left subarray are smaller than all elements in the right subarray