Strony

poniedziałek, 25 marca 2013

nth permutation in a lexicographical order


Problem:

Somebody is generating permutations of a given list of elements in a lexicographical order. What is the value of say nth permutation?

Brute force solution is to generate them all, but in that case you'll spend quite a lot of time generating useless permutations - O(n!). So here is the easy way:




Brak komentarzy:

Prześlij komentarz