The Steinhaus–Johnson–Trotter algorithm or Johnson–Trotter algorithm, also called plain changes, is an algorithm named after Hugo Steinhaus, Selmer M. Johnson and Hale F. Trotter that generates all of the permutations of elements. Each permutation in the sequence that it generates differs from the previous permutation by swapping two adjacent elements of the sequence. Equivalently, this algorithm finds a Hamiltonian cycle in the permutohedron. This method was known already to 17th-century English change ringers, and calls it "perhaps the most prominent permutation enumeration algorithm". A version of the algorithm can be implemented in such a way that the average time per permutation is constant. As well as being simple and computationally efficient, this algorithm has the advantage that subsequent computations on the permutations that it generates may be sped up because of the similarity between consecutive permutations that it generates. Algorithm The sequence of permutations generated by the Steinhaus–Johnson–Trotter algorithm has a natural recursive structure, that can be generated by a recursive algorithm. However the actual Steinhaus–Johnson–Trotter algorithm does not use recursion, instead computing the same sequence of permutations by a simple iterative method. A later improvement allows it to run in constant average time per permutation. Recursive structure The sequence of permutations for a given number can be formed from the sequence of permutations for by placing the number into each possible position in each of the shorter permutations. The Steinhaus–Johnson–Trotter algorithm follows this structure: the sequence of permutations it generates consists of blocks of permutations, so that within each block the permutations agree on the ordering of the numbers from 1 to and differ only in the position of . The blocks themselves are ordered recursively, according to the Steinhaus–Johnson–Trotter algorithm for one less element. Within each block, the positions in which is placed occur either in descending or ascending order, and the blocks alternate between these two orders: the placements of in the first block are in descending order, in the second block they are in ascending order, in the third block they are in descending order, and so on. Thus, from the single permutation on one element, one may place the number 2 in each possible position in descending order to form a list of two permutations on two elements, Then, one may place the number 3 in each of three different positions for these two permutations, in descending order for the first permutation 1 2, and