|
|
вернуться в форумОбщий форумHow to compute the inversions? The problems is to find the inversions( given a permutation of the numbers 1,2,3,...,n (a1,a2,...,an) find number of pairs (ai,aj) such that i < j and ai>aj How to solve this? I think I know a solution with complexity n*sqrt (n), is there better? And some good realization? If you know, you can write to me on : vladovasilev@abv.bg Thanks! :) O(n log n) :) (-) > The problems is to find the inversions( given a permutation of the > numbers 1,2,3,...,n (a1,a2,...,an) find number of pairs (ai,aj) such > that i < j and ai>aj > How to solve this? I think I know a solution with complexity n*sqrt > (n), is there better? And some good realization? If you know, you can > write to me on : vladovasilev@abv.bg > > Thanks! :) Don't you read Cormen? (+) Look in Cormen's book on algorithms (chapter 1) :) |
|
|