How to find the k-th permutation for a given k? Find the
algorithm.
Consider the set of all permutations on 1, : : : , n, sorted lexicographically. How to find the k-th permutation, for a given k? And how, for a given permutation T, to determine its index k among all the permutations of 1, . . . , n?
(2, 1, 3), the algorithm should return that it is the 3rd permutation.
(The complete list in order is (1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1).)