Skip to main content

Generating Gray Codes in O(1) Worst-Case Time per Word

  • Conference paper
  • First Online:

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

Abstract

We give a definition of Gray code that, unlike the standard “minimal change” definition, is satisfied by the word-lists in the literature called “Gray codes” and we give several examples to illustrate the various concepts of minimality. We show that a non-recursive generation algorithm can be obtained for a word-list such that all the words with the same prefix (or, equivalently, suffix) are consecutive and that the Bitner-Ehrlich-Reingold method of generating each word in a time bounded by a constant works under the additional condition that in the interval of words with the same prefix or suffix the next letter assumes at least two values. Finally we generalize this method so that it works under a weaker condition satisfied by almost all the Gray codes in the literature: if the next letter assumes only one value, then the interval contains only one word.

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

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Gray, F.: Pulse Code Communication. U.S. Patent 2 632 058 (March 17, 1953)

    Google Scholar 

  2. Liu, C.N., Tang, D.T.: Algorithm 452, Enumerating M out of N objects. Comm. ACM 16 (1973) 485

    Article  Google Scholar 

  3. Eades, P., McKay, B.: An Algorithm for Generating Subsets to Fixed Size with a Strong Minimal Interchange Property. Information Processing Letters 19 (1984) 131–133

    Article  MATH  MathSciNet  Google Scholar 

  4. Johnson, S.M.: Generation of Permutations by Adjacent Transpositions. Mathematics of Computation 17 (1963) 282–285

    Article  MATH  MathSciNet  Google Scholar 

  5. Trotter, H.F.: Algorithm 115: Perm. Comm. ACM 5 (1962) 434–435

    Article  Google Scholar 

  6. Nijenhuis, A., Wilf, H.S.: Combinatorial Algorithms for Computers and Calculators, second edition. Academic Press, N.Y. (1978)

    MATH  Google Scholar 

  7. Chase, P.J.: Combination Generation and Graylex Ordering. Proceedings of the 18th Manitoba Conference on Numerical Mathematics and Computing, Winnipeg, 1988. Congressus Numerantium 69 (1989) 215–242

    MathSciNet  Google Scholar 

  8. Ruskey, F.: Simple Combinatorial Gray Codes Constructed by Reversing Sublists. L.N.C.S. 762 (1993) 201–208

    MathSciNet  Google Scholar 

  9. Vajnovszki, V., Walsh, T.R.: A loopless two-close Gray code algorithm for listing k-ary Dyck words. Submitted for publication

    Google Scholar 

  10. Ruskey, F., Proskurowski, A.: Generating Binary Trees by Transpositions. J. Algorithms 11 (1990) 68–84

    Article  MATH  MathSciNet  Google Scholar 

  11. Bultena, B., Ruskey, F.: An Eades-McKay Algorithm for Well-Formed Parentheses Strings. Inform. Process. Lett. 68 (1998), no. 5, 255–259

    Article  MathSciNet  Google Scholar 

  12. Savage, C.: Gray Code Sequences of Partitions. Journal of Algorithms 10 (1989) 577–595

    Article  MATH  MathSciNet  Google Scholar 

  13. Walsh, T.R.: A Simple Sequencingan d Ranking Method that Works on Almost All Gray Codes. Research Report No. 243, Department of Mathematics and Computer Science, Université du Québec à Montréal (April 1995)

    Google Scholar 

  14. Ehrlich, G.: Loopless Algorithms for Generating Permutations, Combinations, and Other Combinatorial Configurations: J. ACM 20 (1973) 500–513

    Article  MATH  MathSciNet  Google Scholar 

  15. Bitner, J.R., Ehrlich, G., Reingold, E.M.: Efficient Generation of the Binary Reflected Gray Code and its Applications. Comm. ACM 19 (1976) 517–521

    Article  MATH  MathSciNet  Google Scholar 

  16. Joichi, J.T., White, D.E., Williamson, S.G.: Combinatorial Gray Codes. SIAM J. Computing 9 (1980) 130–141

    Article  MATH  MathSciNet  Google Scholar 

  17. Walsh, T.R.: Gray Codes for Involutions. JCMCC 36 (2001) 95–118

    MATH  Google Scholar 

  18. Walsh, T.R.: Generation of Well-Formed Parenthesis Strings in Constant Worst-Case Time. J. Algorithms 29 (1998) 165–173

    Article  MATH  MathSciNet  Google Scholar 

  19. Roelants van Baronaigien, D.: A Loopless Gray-Code Algorithm for Listing k-ary Trees. J. Algorithms 35 (2000), no. 1, 100–107

    Article  MATH  MathSciNet  Google Scholar 

  20. Williamson, S.G.: Combinatorics for Computer Science. Computer Science Press, Rockville (1985)

    Google Scholar 

  21. Roelants van Baronaigien, D.: Constant Time Generation of Involutions. Congressus Numerantium 90 (1992) 87–96

    MathSciNet  Google Scholar 

  22. Vajnovszki, V.: Generating Multiset Permutations. Accepted for publication in Theoretical Computer Science

    Google Scholar 

  23. Klingsberg, P.: A Gray Code for Compositions. Journal of Algorithms 3 (1982) 41–44

    Article  MATH  MathSciNet  Google Scholar 

  24. Walsh, T.R.: Loop-free sequencing of bounded integer compositions, JCMCC 33 (2000) 323–345

    MATH  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2003 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

Walsh, T. (2003). Generating Gray Codes in O(1) Worst-Case Time per Word. In: Calude, C.S., Dinneen, M.J., Vajnovszki, V. (eds) Discrete Mathematics and Theoretical Computer Science. DMTCS 2003. Lecture Notes in Computer Science, vol 2731. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-45066-1_5

Download citation

  • DOI: https://doi.org/10.1007/3-540-45066-1_5

  • Published:

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-40505-4

  • Online ISBN: 978-3-540-45066-5

  • eBook Packages: Springer Book Archive

Publish with us

Policies and ethics