Steinhaus-Johnson-Trotter algorithm

Steinhaus-Johnson-Trotter algorithm

The Steinhaus-Johnson-Trotter algorithm or Johnson-Trotter algorithm is an algorithm which generates permutations by transposing elements.

Algorithm

The algorithm is setup with the idea that only one set of neighbors needs to swap positions and that there need only be 1 swap to generate the next permutation. To accommodate this, there needs to be an extra data element added: direction of mobility (ie direction of the swap). This direction is either left or right, but is initialized to the left. Pseudocode:

Initialize the first permutation 1 2 ... "n" all mobile to the left while there exists a mobile integer find the largest mobile integer "k" swap "k" and the adjacent integer in the direction of "k"'s mobility for each integer "l" if "l" > "k" then reverse the direction of mobility of "l"

An integer is said to be mobile if, in the direction of its mobility, the nearest integer is less than the current integer. Note that if an integer is to the far left and its mobility is to the left, it is not mobile. Similarly, if an integer is to the far right and its mobility is to the right, it is also not mobile.


=Example: n=3=

Using the Steinhaus-Johnson-Trotter algorithm with n = 3 would result in the following: <1 <2 <3 <1 <3 <2 <3 <1 <2 3> <2 <1 <2 3> <1 <2 <1 3>Note that this hits all 6 permutations.


=Example: n=4=

Using the Steinhaus-Johnson-Trotter algorithm with n = 4 would result in the following: <1 <2 <3 <4 <1 <2 <4 <3 <1 <4 <2 <3 <4 <1 <2 <3 4> <1 <3 <2 <1 4> <3 <2 <1 <3 4> <2 <1 <3 <2 4> <3 <1 <2 <4 <3 <1 <4 <2 <3 <4 <1 <2 <4 <3 <1 <2 4> 3> <2 <1 3> 4> <2 <1 3> <2 4> <1 3> <2 <1 4> <2 3> <1 <4 <2 3> <4 <1 <2 <4 3> <1 <4 <2 3> <1 4> <2 <1 3> <2 4> <1 3> <2 <1 4> 3> <2 <1 3> 4>Note that this hits all 24 permutations

ee also

* Fisher-Yates shuffle

External links

* [http://www.theory.csc.uvic.ca/%7Ecos/inf/perm/PermInfo.html Implementation of the Steinhaus-Johnson-Trotter algorithm]
* [http://www.cut-the-knot.org/Curriculum/Combinatorics/JohnsonTrotter.shtml Counting And Listing All Permutations: Johnson-Trotter Method] at cut-the-knot

References

*


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • List of mathematics articles (S) — NOTOC S S duality S matrix S plane S transform S unit S.O.S. Mathematics SA subgroup Saccheri quadrilateral Sacks spiral Sacred geometry Saddle node bifurcation Saddle point Saddle surface Sadleirian Professor of Pure Mathematics Safe prime Safe… …   Wikipedia

  • Permutation — For other uses, see Permutation (disambiguation). The 6 permutations of 3 balls In mathematics, the notion of permutation is used with several slightly different meanings, all related to the act of permuting (rearranging) objects or values.… …   Wikipedia

  • Change ringing — Triples redirects here. For other uses, see Triple (disambiguation). Bell ringing practice in Stoke Gabriel parish church, Devon, England Change ringing is the art of ringing a set of tuned bells in a series of mathematical patterns called… …   Wikipedia

  • Hamiltonian path — This article is about the overall graph theory concept of a Hamiltonian path. For the specific problem of determining whether a Hamiltonian path or cycle exists in a given graph, see Hamiltonian path problem. A Hamiltonian cycle in a dodecahedron …   Wikipedia

  • List of terms relating to algorithms and data structures — The [http://www.nist.gov/dads/ NIST Dictionary of Algorithms and Data Structures] is a reference work maintained by the U.S. National Institute of Standards and Technology. It defines a large number of terms relating to algorithms and data… …   Wikipedia

  • Список терминов, относящихся к алгоритмам и структурам данных —   Это служебный список статей, созданный для координации работ по развитию темы.   Данное предупреждение не устанавливается на информационные списки и глоссарии …   Википедия

  • Список терминов — Список терминов, относящихся к алгоритмам и структурам данных   Это сл …   Википедия

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”