Generating Signed Permutations by Twisting Two-Sided Ribbons

  • Conference paper
  • First Online:
LATIN 2024: Theoretical Informatics (LATIN 2024)

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 14578))

Included in the following conference series:

  • 155 Accesses

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Subscribe and save

Springer+ Basic
EUR 32.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or Ebook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Chapter
USD 29.95
Price excludes VAT (Canada)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 59.99
Price excludes VAT (Canada)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 74.99
Price excludes VAT (Canada)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free ship** worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Similar content being viewed by others

Notes

  1. 1.

    Manufacturers refer to this type of ribbon as single face as only one side is polished.

  2. 2.

    If the permutation is stored in a BLL instead of an array, then loopless is possible [35].

  3. 3.

    The eponymous Gray code by Gray [10] also demonstrates Stigler’s law [32]: [9, 13].

  4. 4.

    Physically, a ribbon moves above or below its neighbor, but that is not relevant here.

  5. 5.

    \(\overleftarrow{s_1}\) and \(\overrightarrow{s_1}\) are omitted as they equal other swaps. In fact, the swaps are all jumps [12].

  6. 6.

    Unsigned ruler sequences are palindromes, so \(^R\)’s can be added to (8) to mirror (10).

  7. 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. 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

  1. 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)

    Article  MathSciNet  Google Scholar 

  2. Compton, R.C., Gill Williamson, S.: Doubly adjacent Gray codes for the symmetric group. Linear Multilinear Algebra 35(3–4), 237–293 (1993)

    Article  MathSciNet  Google Scholar 

  3. Corbett, P.F.: Rotator graphs: an efficient topology for point-to-point multiprocessor networks. IEEE Trans. Parallel Distrib. Syst. 3(5), 622–626 (1992)

    Article  Google Scholar 

  4. Duato, J., Yalamanchili, S., Ni, L.: Interconnection Networks. Morgan Kaufmann, Burlington (2003)

    Google Scholar 

  5. Duckworth, R., Stedman, F.: Tintinnalogia: Or, The Art of Ringing. London (1668)

    Google Scholar 

  6. Ehrlich, G.: Loopless algorithms for generating permutations, combinations, and other combinatorial configurations. J. ACM 20(3), 500–513 (1973)

    Article  MathSciNet  Google Scholar 

  7. Fertin, G., Labarre, A., Rusu, I., Vialette, S., Tannier, E.: Combinatorics of Genome Rearrangements. MIT Press, Cambridge (2009)

    Book  Google Scholar 

  8. Ganapathi, P., Chowdhury, R.: A unified framework to discover permutation generation algorithms. Comput. J. 66(3), 603–614 (2023)

    Article  MathSciNet  Google Scholar 

  9. Gardner, M.: Curious properties of the Gray code and how it can be used to solve puzzles. Sci. Am. 227(2), 106 (1972)

    Article  Google Scholar 

  10. Gray, F.: Pulse code communication. United States Patent Number 2632058 (1953)

    Google Scholar 

  11. 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)

    Google Scholar 

  12. 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)

    Google Scholar 

  13. Heath, F.: Origins of the binary code. Sci. Am. 227(2), 76–83 (1972)

    Article  Google Scholar 

  14. Hindenburg, C.F.: Sammlung combinatorisch-analytischer Abhandlungen, vol. 1. ben Gerhard Fleischer dem Jungern (1796)

    Google Scholar 

  15. Holroyd, A.E., Ruskey, F., Williams, A.: Shorthand universal cycles for permutations. Algorithmica 64, 215–245 (2012)

    Article  MathSciNet  Google Scholar 

  16. Johnson, S.M.: Generation of permutations by adjacent transposition. Math. Comput. 17(83), 282–285 (1963)

    Article  MathSciNet  Google Scholar 

  17. Knuth, D.E.: Art of Computer Programming, Volume 4, Fascicle 4, The: Generating All Trees-History of Combinatorial Generation. Addison-Wesley, Boston (2013)

    Google Scholar 

  18. 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)

    Article  MathSciNet  Google Scholar 

  19. 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

    Chapter  Google Scholar 

  20. 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)

    Google Scholar 

  21. 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)

    Google Scholar 

  22. Mütze, T.: Combinatorial Gray codes-an updated survey. ar**v preprint ar**v:2202.01280 (2022)

  23. OEIS Foundation Inc.: The On-Line Encyclopedia of Integer Sequences (2023). http://oeis.org

  24. Ord-Smith, R.: Generation of permutation sequences: part 1. Comput. J. 13(2), 152–155 (1970)

    Article  Google Scholar 

  25. Qiu, Y.F.: Greedy and speedy: new iterative gray code algorithms. Bachelor’s thesis, Williams College (2024)

    Google Scholar 

  26. Ruskey, F.: Combinatorial generation. Preliminary working draft. University of Victoria, Victoria, BC, Canada 11, 20 (2003)

    Google Scholar 

  27. Savage, C.: A survey of combinatorial Gray codes. SIAM Rev. 39(4), 605–629 (1997)

    Article  MathSciNet  Google Scholar 

  28. Sawada, J., Williams, A.: Greedy flip** of pancakes and burnt pancakes. Discret. Appl. Math. 210, 61–74 (2016)

    Article  MathSciNet  Google Scholar 

  29. Sawada, J., Williams, A.: Successor rules for flip** pancakes and burnt pancakes. Theoret. Comput. Sci. 609, 60–75 (2016)

    Article  MathSciNet  Google Scholar 

  30. Sedgewick, R.: Permutation generation methods. ACM Comput. Surv. (CSUR) 9(2), 137–164 (1977)

    Article  MathSciNet  Google Scholar 

  31. Steinhaus, H.: One hundred problems in elementary mathematics. Courier Corporation (1979)

    Google Scholar 

  32. Stigler, S.M.: Stigler’s law of eponymy. Trans. New York Acad. Sci. 39(1 Series II), 147–157 (1980)

    Google Scholar 

  33. 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)

    Google Scholar 

  34. Trotter, H.F.: Algorithm 115: perm. Commun. ACM 5(8), 434–435 (1962)

    Article  Google Scholar 

  35. 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

    Chapter  Google Scholar 

  36. 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

    Chapter  Google Scholar 

  37. Williams, A.: Signed-plain-changes (2024). https://gitlab.com/combinatronics/signed-plain-changes

  38. Zaks, S.: A new algorithm for generation of permutations. BIT Numer. Math. 24(2), 196–204 (1984)

    Article  MathSciNet  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Aaron Williams .

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

Rights and permissions

Reprints and permissions

Copyright information

© 2024 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

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)

Publish with us

Policies and ethics

Navigation