Answer
algorithm for producing all permutations of a
set of n elements based on the correspondence
Work Step by Step
procedure Cantor permutation(n, i: integers with
n ≥ 1 and 0 ≤ i < n !)
x := n
for j := 1 to n
pj := 0
for k := 1 to n − 1
c := x/(n − k)!; x := x − c(n − k)!; h := n
while ph \ne 0
h := h − 1
for j := 1 to c
h := h − 1
while ph = 0
h := h − 1
ph := n − k + 1
h := 1
while ph \ne= 0
h := h + 1
ph := 1
{p1p2 . . . pn is the permutation corresponding
to i}