Inversion Count (Merge Sort)

Array Presets

Algorithm Loop

1. Divide Subarrays Pending
2. Compare & Count Pending
3. Merge & Copy Pending

The Merge Trick

Both the left and right halves are already sorted. If we find that arr[i] > arr[j], then every element from i to the end of the left half is also greater than arr[j].

We instantly count all of them: +(mid - i + 1) inversions!

Live Console Log

Waiting for actions...

Total Inversions

0
Original / Main Array
Temp Array (Merging)