Abstract
We provide a simple approach to generating all \(2^n \cdot n!\) signed permutations of \([n] = \{1,2,\ldots ,n\}\). Our solution generalizes the most famous ordering of permutations: plain changes (Steinhaus-Johnson-Trotter algorithm). In plain changes, the n! permutations of [n] are ordered so that successive permutations differ by swap** a pair of adjacent symbols, and the order is often visualized as a weaving pattern on n ropes. Here we model a signed permutation as n ribbons with two distinct sides, and each successive configuration is created by twisting (i.e., swap** and turning over) two neighboring ribbons or a single ribbon. By greedily prioritizing 2-twists of large symbols then 1-twists of large symbols, we create a signed version of plain change’s memorable zig-zag pattern. We also provide a loopless implementation (i.e., worst-case \(\mathcal {O}(1)\)-time per object) by enhancing the well-known mixed-radix Gray code algorithm.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
Notes
- 1.
Manufacturers refer to this type of ribbon as single face as only one side is polished.
- 2.
If the permutation is stored in a BLL instead of an array, then loopless is possible [35].
- 3.
- 4.
Physically, a ribbon moves above or below its neighbor, but that is not relevant here.
- 5.
\(\overleftarrow{s_1}\) and \(\overrightarrow{s_1}\) are omitted as they equal other swaps. In fact, the swaps are all jumps [12].
- 6.
- 7.
Surprisingly, this sequence is not yet in the Online Encyclopedia of Integer Sequences, nor is the signed downstairs sequence \(\textsf{ruler}\pm (n{,}n{-}1{,}{.}{.}{.}{,}2) = \textsf{ruler}\pm (n{,}n{-}1{,}{.}{.}{.}{,}1)-1 = 1,2,-1,2,1,3,-1,-2,1,-2,-1,3,1,2,-1,2,1,3,-1,-2,1,-2,-1,4,\ldots \).
- 8.
Negative indices give right-to-left access in Python. So the ruler entry -1 selects the last function fns[-1] = twist(p,q,n,1) (i.e., 2-twist n right). Notes: v=v is for binding; slice notation [-1::-1] reverses a list; indices are reversed from Sect. 4.
References
Cameron, B., Sawada, J., Therese, W., Williams, A.: Hamiltonicity of k-sided pancake networks with fixed-spin: efficient generation, ranking, and optimality. Algorithmica 85(3), 717–744 (2023)
Compton, R.C., Gill Williamson, S.: Doubly adjacent Gray codes for the symmetric group. Linear Multilinear Algebra 35(3–4), 237–293 (1993)
Corbett, P.F.: Rotator graphs: an efficient topology for point-to-point multiprocessor networks. IEEE Trans. Parallel Distrib. Syst. 3(5), 622–626 (1992)
Duato, J., Yalamanchili, S., Ni, L.: Interconnection Networks. Morgan Kaufmann, Burlington (2003)
Duckworth, R., Stedman, F.: Tintinnalogia: Or, The Art of Ringing. London (1668)
Ehrlich, G.: Loopless algorithms for generating permutations, combinations, and other combinatorial configurations. J. ACM 20(3), 500–513 (1973)
Fertin, G., Labarre, A., Rusu, I., Vialette, S., Tannier, E.: Combinatorics of Genome Rearrangements. MIT Press, Cambridge (2009)
Ganapathi, P., Chowdhury, R.: A unified framework to discover permutation generation algorithms. Comput. J. 66(3), 603–614 (2023)
Gardner, M.: Curious properties of the Gray code and how it can be used to solve puzzles. Sci. Am. 227(2), 106 (1972)
Gray, F.: Pulse code communication. United States Patent Number 2632058 (1953)
Hannenhalli, S., Pevzner, P.A.: Transforming cabbage into turnip: polynomial algorithm for sorting signed permutations by reversals. In: Proceedings of the 27th Annual ACM Symposium on Theory of Computing (STOC 1995), pp. 178–189. ACM (1995)
Hartung, E., Hoang, H., Mütze, T., Williams, A.: Combinatorial generation via permutation languages. I. fundamentals. Trans. Am. Math. Soc. 375(04), 2255–2291 (2022)
Heath, F.: Origins of the binary code. Sci. Am. 227(2), 76–83 (1972)
Hindenburg, C.F.: Sammlung combinatorisch-analytischer Abhandlungen, vol. 1. ben Gerhard Fleischer dem Jungern (1796)
Holroyd, A.E., Ruskey, F., Williams, A.: Shorthand universal cycles for permutations. Algorithmica 64, 215–245 (2012)
Johnson, S.M.: Generation of permutations by adjacent transposition. Math. Comput. 17(83), 282–285 (1963)
Knuth, D.E.: Art of Computer Programming, Volume 4, Fascicle 4, The: Generating All Trees-History of Combinatorial Generation. Addison-Wesley, Boston (2013)
Korsh, J., LaFollette, P., Lipschutz, S.: A loopless implementation of a Gray code for signed permutations. Publications de l’Institut Mathematique 89(103), 37–47 (2011)
Liptak, Z., Masillo, F., Navarro, G., Williams, A.: Constant time and space updates for the sigma-tau problem. In: Nardini, F.M., Pisanti, N., Venturini, R. (eds.) SPIRE 2023. LNCS, vol. 14240, pp. 323–330. Springer, Cham (2023). https://doi.org/10.1007/978-3-031-43980-3_26
Merino, A., Mutze, T.: Traversing combinatorial 0/1-polytopes via optimization. In: 2023 IEEE 64th Annual Symposium on Foundations of Computer Science (FOCS), pp. 1282–1291 (2023)
Merino, A., Mutze, T., Williams, A.: All your bases are belong to us: listing all bases of a matroid by greedy exchanges. In: 11th International Conference on Fun with Algorithms (FUN 2022), vol. 226, p. 22. Schloss Dagstuhl-Leibniz-Zentrum für Informatik (2022)
Mütze, T.: Combinatorial Gray codes-an updated survey. ar**v preprint ar**v:2202.01280 (2022)
OEIS Foundation Inc.: The On-Line Encyclopedia of Integer Sequences (2023). http://oeis.org
Ord-Smith, R.: Generation of permutation sequences: part 1. Comput. J. 13(2), 152–155 (1970)
Qiu, Y.F.: Greedy and speedy: new iterative gray code algorithms. Bachelor’s thesis, Williams College (2024)
Ruskey, F.: Combinatorial generation. Preliminary working draft. University of Victoria, Victoria, BC, Canada 11, 20 (2003)
Savage, C.: A survey of combinatorial Gray codes. SIAM Rev. 39(4), 605–629 (1997)
Sawada, J., Williams, A.: Greedy flip** of pancakes and burnt pancakes. Discret. Appl. Math. 210, 61–74 (2016)
Sawada, J., Williams, A.: Successor rules for flip** pancakes and burnt pancakes. Theoret. Comput. Sci. 609, 60–75 (2016)
Sedgewick, R.: Permutation generation methods. ACM Comput. Surv. (CSUR) 9(2), 137–164 (1977)
Steinhaus, H.: One hundred problems in elementary mathematics. Courier Corporation (1979)
Stigler, S.M.: Stigler’s law of eponymy. Trans. New York Acad. Sci. 39(1 Series II), 147–157 (1980)
Suzuki, Y., Sawada, N., Kaneko, K.: Hamiltonian cycles and paths in burnt pancake graphs. In: Proceedings of the ISCA 18th International Conference on Parallel and Distributed Computing Systems, pp. 85–90 (2005)
Trotter, H.F.: Algorithm 115: perm. Commun. ACM 5(8), 434–435 (1962)
Williams, A.: \(O(1)\)-time unsorting by prefix-reversals in a boustrophedon linked list. In: Boldi, P., Gargano, L. (eds.) FUN 2010. LNCS, vol. 6099, pp. 368–379. Springer, Heidelberg (2010). https://doi.org/10.1007/978-3-642-13122-6_35
Williams, A.: The greedy Gray code algorithm. In: Dehne, F., Solis-Oba, R., Sack, J.R. (eds.) WADS 2013. LNCS, vol. 8037, pp. 525–536. Springer, Heidelberg (2013). https://doi.org/10.1007/978-3-642-40104-6_46
Williams, A.: Signed-plain-changes (2024). https://gitlab.com/combinatronics/signed-plain-changes
Zaks, S.: A new algorithm for generation of permutations. BIT Numer. Math. 24(2), 196–204 (1984)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
A Python Implementation
A Python Implementation
A loopless implementation of our signed plain change order \(\textsf{twisted}(n)\) in Python 3. Entries in the twisted ruler sequence \(\textsf{ruler}\pm (n,n{-}1,\ldots ,2,1,2,2,\ldots ,2)\) select the 2-twist or 1-twist (i.e., flip) to applyFootnote 8. Programs are available online [37].
![figure m](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-55598-5_8/MediaObjects/545566_1_En_8_Figm_HTML.png)
Rights and permissions
Copyright information
© 2024 The Author(s), under exclusive license to Springer Nature Switzerland AG
About this paper
Cite this paper
Qiu, Y., Williams, A. (2024). Generating Signed Permutations by Twisting Two-Sided Ribbons. In: Soto, J.A., Wiese, A. (eds) LATIN 2024: Theoretical Informatics. LATIN 2024. Lecture Notes in Computer Science, vol 14578. Springer, Cham. https://doi.org/10.1007/978-3-031-55598-5_8
Download citation
DOI: https://doi.org/10.1007/978-3-031-55598-5_8
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-031-55597-8
Online ISBN: 978-3-031-55598-5
eBook Packages: Computer ScienceComputer Science (R0)