
8
Get Them All. Algorithms and
Permutations.
8.1 Generating Permutations
8.1.1 Generating All n-Permutations
If we want to write a computer program to test a conjecture concerning per-
mutations, we need to have an efficient method to generate all n-permutations
for our machine. If the conjecture only concerns permutations with some re-
strictions, we can save a lot of time and effort by having a fast way to generate
only those permutations with the required property.
One can certainly list all permutations lexicographically. That is, let us
define a partial order on the set of all n-permutations as follows. Let p =
p
1
p
2
···p
n
<q
1
q
2
···q
n
if for the smallest