In ranking systems, we want to be able to count the inversions between two different rankings of the same objects. That is, if we take one list of rankings, we want to tell how many inversions are required to get to the other one.
We recursively sort the list to be counted and the n find its inversions by merging back up.
We sort the lists recursively, counting the number of inversions, then add the inversions for merging.
We merge by maintaining a pointer into each list, initialized to the front. We keep count of the inversions. While neither list is empty, we add the smaller item being pointed to to the output list, and if the item in the rightmost list is smaller, we increment the number of inversions.
This runs in O(nlogn) time for an n-element list.