## Permutation Generation Methods*

### BibTeX

@MISC{Sedgewlck_permutationgeneration,

author = {Robert Sedgewlck},

title = {Permutation Generation Methods*},

year = {}

}

### OpenURL

### Abstract

This paper surveys the numerous methods that have been proposed for permutatmn enumeration by computer. The various algorithms which have been developed over the years are described in detail, and zmplemented in a modern ALc, oL-hke language. All of the algorithms are derived from one rumple control structure.

### Citations

30 |
Algorithm 115
- Trotter
- 1962
(Show Context)
Citation Context ...r improvements to this algorithm and its implementation. Adjacent Exchanges Perhaps the most prominent permutation enumeration algorithm was formulated in 1962 by S. M. Johnson [20] and H. F. Trotter =-=[45]-=-, apparently independently. They discovered that it was possible to generate all N! permutations of N elements with N!-1 exchanges of adjacent elements. Computing Surveys, Col 9, No 2, June 1977s144 •... |

4 |
Sorting and Searching," The Art of Computer Programming
- Knuth
- 1973
(Show Context)
Citation Context ...p: if N>2 then permutatmns(N-1) endif; while c<N: P[B [N,c]]:=:P[N]; c:=c+l repeat end; This program uses the looping control construct loop • • • while • • • repeat which is described by D. E. Knuth =-=[23]-=-. Statements between loop and repeat are iterated: when the while condition fails, the loop is exited. If the while were placed immediately following the loop, then the statement would be like a norma... |

3 |
Combinatorial analysis and computers
- Hall, Knuth
- 1965
(Show Context)
Citation Context ..., it seems to be inherent in lexicographic generation. The furst algorithm that we shall consider is based on the idea of producing each permutation from its lexicographic predecessor. Hall and Knuth =-=[15]-=- found that the method has been rediscovered many times since being published in 1812 by Fischer and Krause [14]. The ideas involved first appear in the modern literature in a rudimentary form in an a... |

1 |
PERM (Algorithm 6
- BOOTIOYD
- 1965
(Show Context)
Citation Context ...The fastest permutation algorithms operate in this way: All N! permutations of N elements are produced by a sequence of N!-1 exchanges. We shall use the notation Permutation Generation Methods • 139 P=-=[1]-=-:=:P[2] to mean "exchange the contents of array elements P[1] and P[2]". This instruction gives both arrangements of the elements P[1], P[2] (i.e., the arrangement before the exchange and the one afte... |

1 |
Permutation of the elements of a vector (Algomthm 29)"; and "Fast permutation of the elements of a vector (Algorithm 30
- BOOTHROVD
- 1967
(Show Context)
Citation Context ...Lrst N = 5 subnetwork leaves the elements in the order C D E B A F, so that B[6,1] must be 3 to get the E into P[6], leaving C D F B A E. The second N = 5 subnetwork then leaves F B A D C E, so that B=-=[6,2]-=- must be 4 to get the D into P[6], etc. Table 2 is the full table for N <- 12 generated this way; we could generate permutations with Algorithm 1 by storing these N(N- 1) indices. There is no reason t... |

1 |
Permutations with repetitious (Algomthm 306
- BaATLEY
- 1967
(Show Context)
Citation Context ...y now well prepared. We shall begin by assuming that P[1],...P[N] are distinct. Otherwise, the problem is quite different, since it is usual to produce a lexicographic listing with no duplicates (see =-=[3, 9, 39]-=-. We shall fmd it convenient to make use of another primitive operation, reverse(i). This operation inverts the order of the elements in P[1], • • • P[i]; thus, reverse(i) is equivalent tosABCD ABCD A... |

1 |
Permutahon (Algorithm 71
- Cove, R, et al.
- 1961
(Show Context)
Citation Context ...can build up networks for four elements from one of these. For example, using four copies of the f'Lrst network in Fig. 1, we can build a network for N = 4, as shown in Diagram 3. This network fills P=-=[4]-=- with the values D, C, B, A in decreasing alphabetic order (and we could clearly build many similar networks which fill P[4] with the values in other orders). The corresponding network for five elemen... |

1 | A simplified loop-free algorithm for generating permutatlous - aSHOWITZ, N - 1975 |

1 |
W A dzsc~pllne of programm~ng
- DIJKSTRA
- 1976
(Show Context)
Citation Context ...imulated interest in permutation generation by computer per se. The problem is simply stated, but not easily solved, and is often used as an example in programming and correctness. (See, for example, =-=[6]-=-). The study of the various methods that have been proposed for permutation generation is still very instructive today because together they illustrate nicely the relationship between counting, recurs... |

1 |
On a gauntlet thrown by David Gries
- DZgSTaA
- 1976
(Show Context)
Citation Context ...tables are helpful combinatorial devices in the study of several sorting algorithms (see [23]). Another example of the relationship between inversion tables and permutation generation can be found in =-=[7]-=-, where Dijkstra reinvents the Johnson-Trotter method using inversion tables. D. H. Lehmer [26, 27] describes another correspondence that was def'med by D. N. Lehmer as long ago as 1906. To find the p... |

1 |
Random permutation (AIgomthm 235
- DURSTENFELD
- 1964
(Show Context)
Citation Context ...n 4! which begin 2 4 1, then 2.3! which begin 2 4 3 1 or 2 4 3 5, and then 2.2! which begin 24 3 6 lor243 65. A much simpler method than the above two was apparently first published by R. Durstenfeld =-=[8]-=-. (See also [22], p. 125). We notice that P[i] has i-1 elements preceding it, so we can use the c array as follows: ~:=N; loop while ~->2: P[~]:=:P[c[l]+l]; ~:=z-1 repeat; If we take P[1],.--,P[N] to ... |

1 |
Permute (Algorithm 130
- EAVES
- 1962
(Show Context)
Citation Context ...y now well prepared. We shall begin by assuming that P[1],...P[N] are distinct. Otherwise, the problem is quite different, since it is usual to produce a lexicographic listing with no duplicates (see =-=[3, 9, 39]-=-. We shall fmd it convenient to make use of another primitive operation, reverse(i). This operation inverts the order of the elements in P[1], • • • P[i]; thus, reverse(i) is equivalent tosABCD ABCD A... |

1 |
Loopless algomthms for generatmjg permutations, combinations and other combinatorial configurations
- EHRLICH
- 1973
(Show Context)
Citation Context ...on could also apply to Algorithms 1 and 2, but the cases when they exchange nonadjacent elements would have to be handled differently.) The Johnson-Trotter algorithm is often inefficiently formulated =-=[5, 10, 12]-=- because it can be easily described in terms of the values of elements being permuted, rather than their positions. If P[1],. • ", P[N] are originally the integers 1,-.., N, then we might try to avoid... |

1 |
Four combmatomal algomthms (Algomthm 466
- EHRLICH
- 1973
(Show Context)
Citation Context ...the most frequent operation is P[c[N]]:=:P[c[N]+I]; c[N]:=c[N]+l; all but 1IN of the exchanges are of this type. Therefore, we should program this operation separately. (This idea was used by Ehrlich =-=[10, 11]-=-.) Program 4 can be improved by inserting the code given in Program 5 directly after CALL PROCESS Permutation Generation Methods • 161 (As before, we shall write down only the new code, but make refer... |

1 |
Algortthmtc combtnatortcs
- EWN
- 1973
(Show Context)
Citation Context ...on could also apply to Algorithms 1 and 2, but the cases when they exchange nonadjacent elements would have to be handled differently.) The Johnson-Trotter algorithm is often inefficiently formulated =-=[5, 10, 12]-=- because it can be easily described in terms of the values of elements being permuted, rather than their positions. If P[1],. • ", P[N] are originally the integers 1,-.., N, then we might try to avoid... |

1 |
A permutation generation method
- FIKE
- 1975
(Show Context)
Citation Context ...cedure permutattons(N) ; begin c" = 1; loop: P[N]:=:P[c]; if N>2 then permutatmns(N-1) else process end[f; P[c ]: = :P[N]; while c<N: C:=C+I repeat; end; A procedure like this was given by C. T. Fike =-=[13]-=-, who also gave a nonrecursive version [37] which is similar to a program developed independently by S. Pleszczyfiski [35]. These programs are clearly less efficient than the methods of Section 1, whi... |

1 |
Lehrbuch der Combtnattonslehre und der Artthmetzk
- FISCHER, KRAUSE
(Show Context)
Citation Context ...e idea of producing each permutation from its lexicographic predecessor. Hall and Knuth [15] found that the method has been rediscovered many times since being published in 1812 by Fischer and Krause =-=[14]-=-. The ideas involved first appear in the modern literature in a rudimentary form in an algorithm by G. Schrack and M. Shimrat [40]. A full formulation was given by M. Shen in 1962 [41, 42], and Philli... |

1 |
Permutations by Interchanges
- HEAl'
- 1963
(Show Context)
Citation Context ...ractical values of N by constructing the networks as shown in the example above. The complete networks for N = 2,3,4 are shown in Fig. 2. In a short paper that has gone virtually unnoticed, B.R. Heap =-=[16]-=- pointed out several of the ideas above and described a method even simpler than Wells'. (It is not clear whether Heap was influenced by Wells or Boothroyd, since he gives no references.) Heap's metho... |

1 |
Generation of permutations by adchhon,"Math
- HOWELL
- 1962
(Show Context)
Citation Context ... of replacing P[~]:=:P[c[i]]; reverse(i-i); by reverse(i) in Algorithm 8. Computing Surveys, Vol 9, No 2, June 1977 There seem to be no advantages to this method over methods like Algorithm 1. Howell =-=[17, 18]-=- gives a lexicographic method based on treating P[1], • • • ,P[N] as a base-N number, counting in base N, and rejecting numbers whose digits are not distinct. This method is clearly very slow. Random ... |

1 |
Permutation generater (Algorithm 87
- HOWELL
- 1962
(Show Context)
Citation Context ... of replacing P[~]:=:P[c[i]]; reverse(i-i); by reverse(i) in Algorithm 8. Computing Surveys, Vol 9, No 2, June 1977 There seem to be no advantages to this method over methods like Algorithm 1. Howell =-=[17, 18]-=- gives a lexicographic method based on treating P[1], • • • ,P[N] as a base-N number, counting in base N, and rejecting numbers whose digits are not distinct. This method is clearly very slow. Random ... |

1 |
Permutation enumeration: four new permutatmn algorithms
- IvEs
- 1976
(Show Context)
Citation Context ...rithms, but this is apparently due entirely to a simple coding technique (described in Section 3) which he applied to his algorithm and not to the others. Another Iterative Method In 1976, F. M. Ives =-=[19]-=- published an exchange-based method like the JohnsonTrotter method which does represent an improvement. For this method, we build Computing Surveys, Vol 9, No 2, June 1977 I I ~- ^ :[: __l T il[l I : ... |

1 |
Generatlonofpermutations by adjacent transposition
- JOHNSON
- 1963
(Show Context)
Citation Context ...ion 3 we examine further improvements to this algorithm and its implementation. Adjacent Exchanges Perhaps the most prominent permutation enumeration algorithm was formulated in 1962 by S. M. Johnson =-=[20]-=- and H. F. Trotter [45], apparently independently. They discovered that it was possible to generate all N! permutations of N elements with N!-1 exchanges of adjacent elements. Computing Surveys, Col 9... |

1 |
Fundamental algorithms," in The art of computer pro~.rammzng 1
- KNUTH
- 1968
(Show Context)
Citation Context ...done with the high-level language, we shall use a mythical assembly language from which programs on real computers can be easily implemented. (Readers unfamiliar with assembly language should consult =-=[21]-=-.) We shall use load (LD), stere (ST), add (ADD), subtract (SUB), and compare (CMP) instructions which have the general form LABEL OPCODE REGISTER, OPERAND (optional) The first operand will always be ... |

1 |
Seminumerlcal algorithms," m The art ofcom~uter programming 2
- KNUTH
- 1969
(Show Context)
Citation Context ...rmally done by establishing some one-to-one correspondence between a permutation and a random number between 0 andN!-l. (A full treatment of pseudorandom number generation by computer may be found in =-=[22]-=-.) First, we notice that each number between 0 and N!-1 can be represented in a mixed radix system to correspond to an array c[N],c[N-1],. • • ,c[2] with 0 -< c[i] <- ~-1 for 2 -< i -< N. For example,... |

1 |
St,ru, ctured programming with go to statements
- KNUTH
- 1974
(Show Context)
Citation Context ... makes a redundant test i -< N after setting i: =2 in the then clause. This can be avoided in assembly language, as shown in Section 3, or it could be handled with an "event variable" as described in =-=[24]-=-.) We shall examine the structure of this program in detail later. The programs above merely generate all permutations of P[1],. • • ,P[N]; in order to do anything useful, we need to process each perm... |

1 |
An algorithm for generating permutations
- LANaDON
- 1967
(Show Context)
Citation Context ...moved the only test on c[i], and now it is not necessary to maintain the counter array at all! Making this simplification, and changing t to N+I-i, we have an algorithm proposed by G. Langdon in 1967 =-=[25]-=-, shown in Fig. 10. Algorithm 6 (Langdon) t:=l; loop: Q[I]:=P[~] while t<N. ~:=t+l repeat, process; Computing Surveys, Vol 9, No 2, June 1977s152 • R. Sedgewick loop: rotate(t); if P[z]=Q[t] then t:=N... |

1 |
Teaching combinatorial tricks to a computer
- LEHR
- 1960
(Show Context)
Citation Context ...ters in combinatorial mathematics, and it is interesting to study because a number of different approaches can be compared. Surveys of the field have been published previously in 1960 by D. H. Lehmer =-=[26]-=- and in 1970-71 by R. J. Ord-Smith [29, 30]. A new look at the problem is appropriate at this time because several new algorithms have been proposed in the intervening years. Permutation generation ha... |

1 |
The machine tools of combinatemcs," m Applied comb~natortal mathematws
- LEHMER
- 1964
(Show Context)
Citation Context ...the reason it generates so many redundant sequences, is that the recursive procedure restores the permutation to the order it had upon entry. Programs that work this way are called backtrack programs =-=[26, 27, 46, 48]-=-. We can easily apply the same idea to exchange methods like Algorithm 1. For example: procedure permutattons(N) ; begin c" = 1; loop: P[N]:=:P[c]; if N>2 then permutatmns(N-1) else process end[f; P[c... |

1 | Permutation by adjacent interchanges - R - 1965 |

1 |
Generation of permutation sequences Part 1
- -SMITH
- 1970
(Show Context)
Citation Context ...it is interesting to study because a number of different approaches can be compared. Surveys of the field have been published previously in 1960 by D. H. Lehmer [26] and in 1970-71 by R. J. Ord-Smith =-=[29, 30]-=-. A new look at the problem is appropriate at this time because several new algorithms have been proposed in the intervening years. Permutation generation has a long and distinguished history. It was ... |

1 |
Generation of permutation sequences: Part 2
- OaD-SMITH
- 1971
(Show Context)
Citation Context ...it is interesting to study because a number of different approaches can be compared. Surveys of the field have been published previously in 1960 by D. H. Lehmer [26] and in 1970-71 by R. J. Ord-Smith =-=[29, 30]-=-. A new look at the problem is appropriate at this time because several new algorithms have been proposed in the intervening years. Permutation generation has a long and distinguished history. It was ... |

1 |
Generation of permutations in psoudo-lexicographic order (Algorithm 308
- ORD-SMITH
- 1967
(Show Context)
Citation Context ...J. Ord-Smith in 1967 [32]. We would not expect a priori to have a lexicographic algorithm so similar to the normal algorithms, but the recursive formulation makes it obvious. Ord-Smith also developed =-=[31]-=- a "pseudo-lexicographic" algorithm which consists of replacing P[~]:=:P[c[i]]; reverse(i-i); by reverse(i) in Algorithm 8. Computing Surveys, Vol 9, No 2, June 1977 There seem to be no advantages to ... |

1 |
Generation of permutations m lexicographlc order (Algorithm 323
- -SMITH
- 1968
(Show Context)
Citation Context ...cess; loop: if c[l] <~ then P[~ ]:='P[c[l]], reverse(~-l ) , c[~]:=c[z]+ l; ~:=2; process; else c[l]:=l; ~:=~+1 end[f; while ~-<N repeat; This algorithm was first presented by R. J. Ord-Smith in 1967 =-=[32]-=-. We would not expect a priori to have a lexicographic algorithm so similar to the normal algorithms, but the recursive formulation makes it obvious. Ord-Smith also developed [31] a "pseudo-lexicograp... |

1 |
F "Permute (Algorithm 86
- PECK, SCHRACK
- 1962
(Show Context)
Citation Context ...thms in Section 1. This method apparently represents the earliest attempt to get a real computer to generate permutations as quickly as possible. An ALGOL implementation was given by Peck and Schrack =-=[33]-=-. An interesting feature of the TompkinsPaige method, and the reason it generates so many redundant sequences, is that the recursive procedure restores the permutation to the order it had upon entry. ... |

1 |
Permutation of the elements of a vector in lexicographic order (Algorithm 28
- PHmLmS
- 1967
(Show Context)
Citation Context ...he ideas involved first appear in the modern literature in a rudimentary form in an algorithm by G. Schrack and M. Shimrat [40]. A full formulation was given by M. Shen in 1962 [41, 42], and Phillips =-=[34]-=- gives an "optimized" implementation. (Dijkstra [6] cites the problem as an example to illustrate a Permutation Generation Methods • 153 "dramatic improvement in the state of the art" of computer prog... |

1 |
On the generation of permutations
- PLESZCZYNSKL
- 1975
(Show Context)
Citation Context ... while c<N: C:=C+I repeat; end; A procedure like this was given by C. T. Fike [13], who also gave a nonrecursive version [37] which is similar to a program developed independently by S. Pleszczyfiski =-=[35]-=-. These programs are clearly less efficient than the methods of Section 1, which have the same control structure but require many fewer exchanges. Tompkins was careful to point out that it is often po... |

1 | An ~ntroductton to comb~natortal analysts - RIORDAN - 1958 |

1 |
Programming improvements to Fike's algorithm for generating permutations
- ROHL
- 1976
(Show Context)
Citation Context ...: P[N]:=:P[c]; if N>2 then permutatmns(N-1) else process end[f; P[c ]: = :P[N]; while c<N: C:=C+I repeat; end; A procedure like this was given by C. T. Fike [13], who also gave a nonrecursive version =-=[37]-=- which is similar to a program developed independently by S. Pleszczyfiski [35]. These programs are clearly less efficient than the methods of Section 1, which have the same control structure but requ... |

1 | Permutation (Algorithm 317 - ROBXNSON - 1967 |

1 |
Permutations of a set with repetitions (Algorithm 242
- SAG
- 1964
(Show Context)
Citation Context ...y now well prepared. We shall begin by assuming that P[1],...P[N] are distinct. Otherwise, the problem is quite different, since it is usual to produce a lexicographic listing with no duplicates (see =-=[3, 9, 39]-=-. We shall fmd it convenient to make use of another primitive operation, reverse(i). This operation inverts the order of the elements in P[1], • • • P[i]; thus, reverse(i) is equivalent tosABCD ABCD A... |

1 |
Permutation in lexicographlc order (Algorithm 102
- SCHRAK
- 1962
(Show Context)
Citation Context ...overed many times since being published in 1812 by Fischer and Krause [14]. The ideas involved first appear in the modern literature in a rudimentary form in an algorithm by G. Schrack and M. Shimrat =-=[40]-=-. A full formulation was given by M. Shen in 1962 [41, 42], and Phillips [34] gives an "optimized" implementation. (Dijkstra [6] cites the problem as an example to illustrate a Permutation Generation ... |

1 |
On the generation ofpermutatlons and combinations
- SHEN
- 1962
(Show Context)
Citation Context ...cher and Krause [14]. The ideas involved first appear in the modern literature in a rudimentary form in an algorithm by G. Schrack and M. Shimrat [40]. A full formulation was given by M. Shen in 1962 =-=[41, 42]-=-, and Phillips [34] gives an "optimized" implementation. (Dijkstra [6] cites the problem as an example to illustrate a Permutation Generation Methods • 153 "dramatic improvement in the state of the ar... |

1 |
K "Generation ofpermutations in lexicographic order (Algorithm 202
- SHEN
- 1963
(Show Context)
Citation Context ...cher and Krause [14]. The ideas involved first appear in the modern literature in a rudimentary form in an algorithm by G. Schrack and M. Shimrat [40]. A full formulation was given by M. Shen in 1962 =-=[41, 42]-=-, and Phillips [34] gives an "optimized" implementation. (Dijkstra [6] cites the problem as an example to illustrate a Permutation Generation Methods • 153 "dramatic improvement in the state of the ar... |

1 | A handbook of tnteger sequences - SLOANE - 1973 |

1 |
Machine attacks on problems whoso variables are permutations
- TOMPKIN8
- 1956
(Show Context)
Citation Context ...ning years. Permutation generation has a long and distinguished history. It was actually one of the first nontrivial nonnumeric problems to be attacked by computer. In 1956, C. Tompkins wrote a paper =-=[44]-=- describing a number of practical areas 'where permu* Thin work was supported by the Natmnal Science Foundatmn Grant No. MCS75-23738 tation generation was being used to solve problems. Most of the pro... |

1 |
An enumerative technique for a class of combinatorial problems
- WALR
- 1960
(Show Context)
Citation Context ...the reason it generates so many redundant sequences, is that the recursive procedure restores the permutation to the order it had upon entry. Programs that work this way are called backtrack programs =-=[26, 27, 46, 48]-=-. We can easily apply the same idea to exchange methods like Algorithm 1. For example: procedure permutattons(N) ; begin c" = 1; loop: P[N]:=:P[c]; if N>2 then permutatmns(N-1) else process end[f; P[c... |

1 |
Generation of permutations by transposition
- WZLLS
- 1961
(Show Context)
Citation Context ... be easily computed and it is not necessary to precompute the index table. The fLrst of these methods was one of the earliest permutation generation algorithms to be published, by M. B. Wells in 1960 =-=[47]-=-. As modified by J. Boothroyd in 1965 [1, 2], Wells' algorithm amounts to using t~N,c] /~-c ifN is even and c> 2 - 1 otherwise, or, in Algorithm 1, replacing P[B[N,c ]]:=:P[N] by if (N even) and (c>2)... |

1 |
Elements of combtnatortal computtng
- WELLS
- 1971
(Show Context)
Citation Context ...the reason it generates so many redundant sequences, is that the recursive procedure restores the permutation to the order it had upon entry. Programs that work this way are called backtrack programs =-=[26, 27, 46, 48]-=-. We can easily apply the same idea to exchange methods like Algorithm 1. For example: procedure permutattons(N) ; begin c" = 1; loop: P[N]:=:P[c]; if N>2 then permutatmns(N-1) else process end[f; P[c... |

1 | Combinatorial algorithms. (Notes by C. Frankfeldt and - WHITEHEAD - 1973 |