# Given a permutation of 0..N-1, determine the index of that permutation in the lexicographic ordering of all permutations of 0..N-1, in linear time

There are various $\mathcal O(n \log n)$ or worse solutions, but I'm looking for one that runs in $\mathcal O(n)$, or a proof that none exist.

The 2007 paper Linear-time ranking of permutations gives a linear time ranking algorithm for the lexicographic order, assuming arithmetic on numbers of length $O(n\log n)$ takes constant time.

The 2001 paper Ranking and unranking permutations in linear time presents a linear time ranking algorithm not requiring fast arithmetic on large numbers, but not for the lexicographic order. Regarding the latter, it states

The whole problem of ranking permutations in lexicographic order seems inextricably intertwined with the problem of computing the number of inversions in a permutation, and it seems that a major breakthrough will be required to do that computation in linear time, if indeed it it possible at all.

On the other hand, it does mention an $O(n\log n/\log\log n)$ algorithm for ranking permutations in lexicographic order due to Dietz.

Complexity is again of the $O(nlgn)$ order
• I don't understand how this answers the question. The question says the OP already knows of $O(n \lg n)$ time algorithms, and is asking about $O(n)$ algorithms. So, mentioning an $O(n \lg n)$ time algorithm is not answering the question. – D.W. Apr 8 '15 at 21:57
• I still don't see how it answers my comment. Assume the other answer didn't exist (as it is irrelevant for these purposes). How does your answer answer the question that was asked? Take a look at the question again, and then your answer. The question specifically says it does not want an $O(n \lg n)$ time algorithm (the author already knows of $O(n \lg n)$ time algorithms), so how does telling the OP about an $O(n \lg n)$ time algorithm answer the question? – D.W. Apr 9 '15 at 0:25