Counting inversions in an array

前端 未结 30 1944
死守一世寂寞
死守一世寂寞 2020-11-22 04:14

I\'m designing an algorithm to do the following: Given array A[1... n], for every i < j, find all inversion pairs such that A[i] > A[j]

30条回答
  •  情深已故
    2020-11-22 04:41

    Use mergesort, in merge step incremeant counter if the number copied to output is from right array.

提交回复
热议问题