I’m struggling to find efficient algorithm for calculating the rank of a permutation, and vice versa (permutation for a given rank). Can someone give some pointers?
I’m struggling to find efficient algorithm for calculating the rank of a permutation, and
Share
Do you have repeating elements in the array?
If there are only unique elements, the following recursion calculates the rank of
X[m:n]as a permutation of lengthn-m+1:Both
RankandRankOfElementare zero-based (start at 0).Basically,
Rank(permutation) = Rank(first permutation starting with first letter of permutation) + Rank(permutation with first letter deleted), e.g. for stringEDCBAthat meansRank(EDCBA) = Rank(EABCD) + Rank(DCBA).This can be extended to non-unique cases by changing the first term: