Use an order-statistic tree to count the number of inversions in an array of size n in time O(n lg n). Please present your algorithm in a pseudo code.
Two elements a[i] and a[j] form an inversion if a[i] > a[i] and iInput: arr[] = {4, 8, 2, 1)
Input: This array has six inversions: (8,4), (4,2), (8,2), (8,1), (4,1), (2,1).



Answer :

Other Questions