ArticleslgStudy

computer science

Steinhaus–Johnson–Trotter algorithm

Steinhaus–Johnson–Trotter algorithm is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Steinhaus–Johnson–Trotter algorithm rather than just read about it. In short: 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.

Steinhaus–Johnson–Trotter algorithm — main illustration
Steinhaus–Johnson–Trotter algorithm — illustration

Key takeaways

  • Steinhaus–Johnson–Trotter algorithm belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Steinhaus–Johnson–Trotter algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Steinhaus–Johnson–Trotter algorithm from memory before moving on to harder problems.

Reference excerpt

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 n {\displaystyle n} elements. Each two adjacent permutations in the resulting sequence differ by swapping two adjacent permuted elements. Equivalently, this algorithm finds a Hamiltonian cycle in the permutohedron, a polytope whose vertices represent permutations and whose edges represent swaps. This method was known already to 17th-century English change ringers, and Robert Sedgewick 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 generated permutations may be sped up by taking advantage of the similarity between consecutive permutations.

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 n {\displaystyle n} can be formed from the sequence of permutations for n − 1 {\displaystyle n-1} by placing the number n {\displaystyle n} 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 ( n − 1 ) ! {\displaystyle (n-1)!} blocks of permutations, so that within each block the permutations agree on the ordering of the numbers from 1 to n − 1 {\displaystyle n-1} and differ only in the position of n {\displaystyle n} . The blocks themselves are ordered recursively, according to the Steinhaus–Johnson–Trotter algorithm for one less element. Within each block, the positions in which n {\displaystyle n} is placed occur either in descending or ascending order, and the blocks alternate between these two orders: the placements of n {\displaystyle n} 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 then in ascending order for the permutation 2 1:

… excerpt ends here. Continue reading the full article.

Illustrations

Steinhaus–Johnson–Trotter algorithm: The Hamiltonian cycle in the Cayley graph of the symmetric group generated by the Steinhaus–Johnson–Trotter algorithm
The Hamiltonian cycle in the Cayley graph of the symmetric group generated by the Steinhaus–Johnson–Trotter algorithm
Steinhaus–Johnson–Trotter algorithm: Wheel diagram of all permutations of length 
  
    
      
        n
        =
        4
      
    
    {\displaystyle n=4}
  
 generated by the Steinhaus-Johnson-Trotter algorithm, where each permutation is color-coded (1=blue, 2=green, 3=yellow, 4=red).
Wheel diagram of all permutations of length n = 4 {\displaystyle n=4} generated by the Steinhaus-Johnson-Trotter algorithm, where each permutation is color-coded (1=blue, 2=green, 3=yellow, 4=red).

Worked examples

Example 1 — a first encounter with Steinhaus–Johnson–Trotter algorithm

Start with the simplest possible case. Write down what Steinhaus–Johnson–Trotter algorithm claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Steinhaus–Johnson–Trotter algorithm before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Steinhaus–Johnson–Trotter algorithm ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Steinhaus–Johnson–Trotter algorithm

In research
Steinhaus–Johnson–Trotter algorithm appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Steinhaus–Johnson–Trotter algorithm in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Steinhaus–Johnson–Trotter algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Combinatorial algorithms, Permutations, so understanding it makes those chapters shorter.
In everyday life
Look for Steinhaus–Johnson–Trotter algorithm outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Steinhaus–Johnson–Trotter algorithm” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Steinhaus–Johnson–Trotter algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Steinhaus–Johnson–Trotter algorithm means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Steinhaus–Johnson–Trotter algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Steinhaus–Johnson–Trotter algorithm in simple terms?

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.

Why does Steinhaus–Johnson–Trotter algorithm matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Steinhaus–Johnson–Trotter algorithm?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Steinhaus–Johnson–Trotter algorithm.

Tags

  • Combinatorial algorithms
  • Permutations

Keep exploring