maths.kth_lexicographic_permutation

Functions

kth_permutation(k, n)

Finds k'th lexicographic permutation (in increasing order) of

Module Contents

maths.kth_lexicographic_permutation.kth_permutation(k, n)

Finds k’th lexicographic permutation (in increasing order) of 0,1,2,…n-1 in O(n^2) time.

Examples: First permutation is always 0,1,2,…n >>> kth_permutation(0,5) [0, 1, 2, 3, 4]

The order of permutation of 0,1,2,3 is [0,1,2,3], [0,1,3,2], [0,2,1,3], [0,2,3,1], [0,3,1,2], [0,3,2,1], [1,0,2,3], [1,0,3,2], [1,2,0,3], [1,2,3,0], [1,3,0,2] >>> kth_permutation(10,4) [1, 3, 0, 2]