Journal of Mathematical Modelling and Algorithms

, Volume 9, Issue 4, pp 343–356 | Cite as

Loop-Free Gray Code Algorithms for the Set of Compositions



The topic of Gray codes for the set of compositions with non-negative integer parts has been studied by several authors. Klingsberg gave a non-recursive description of a Gray code for this set after the recursive version of Knuth. Recently, Walsh modified Klingsberg’s algorithm to find a Gray code which generates the set of all bounded compositions with non-negative integer parts. In this paper, we present two loopless Gray code algorithms for the set of compositions with positive integer parts.


Compositions Gray codes Loopless algorithms 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Baril, J.-L., Vajnovszki, V.: Gray code for derangements. Disc. App. Math. 140, 207–221 (2004)MATHCrossRefMathSciNetGoogle Scholar
  2. 2.
    Ehrlich, G.: Loopless algorithms for generating permutations, combinations, and other combinatorial configurations. J. Assoc. Comput. Mach. 20, 500–513 (1973)MATHMathSciNetGoogle Scholar
  3. 3.
    Heubach, S., Mansour, T.: Combinatorics of Compositions and Words, Discrete Mathematics and its Applications (Boca Raton). CRC, Boca Raton (2009)CrossRefGoogle Scholar
  4. 4.
    Johson, S.M.: Generating of permutations by adjacent transposition. Math. Comput. 17, 282–285 (1963)CrossRefGoogle Scholar
  5. 5.
    Klingsberg, P.: A Gray code for compositions. J Algorithm 3, 41–44 (1982)MATHCrossRefMathSciNetGoogle Scholar
  6. 6.
    Knuth, D.E.: The Art of Computer Programming, vol. 3, (soring and searching). Addison-Wesley, Reading (1973)Google Scholar
  7. 7.
    Ko, C.W., Ruskey, F.: Generating permutations of a bag by interchanges. Inform. Processing Lett. 41, 263–269 (1992)MATHCrossRefMathSciNetGoogle Scholar
  8. 8.
    Korsh, J.F., LaFollette, P.S.: Loopless array generation of multiset permutations. Technical Report, Department of CIS , PA, USA (2002)Google Scholar
  9. 9.
    Korsh, J.F., Lipschutz, S.: Generating multiset permutations in constant time. J. Algorithm 25, 321–335 (1997)MATHCrossRefMathSciNetGoogle Scholar
  10. 10.
    Mansour, T., Nassar, G.: Gray codes, loopless algorithm and partitions. J. Math. Model Algor. 7.3, 291–310 (2008)CrossRefMathSciNetGoogle Scholar
  11. 11.
    Roelants van Baronaigien, D., Ruskey, F.: Generating permutations with given ups and downs. Disc. Appl. Math. 36:1, 57–65 (1992)MATHCrossRefMathSciNetGoogle Scholar
  12. 12.
    Ruskey, F., Savage, C.D.: Gray codes for set partitions and restricted growth tails. Aust. J. Combin. 10, 85–96 (1994)MATHMathSciNetGoogle Scholar
  13. 13.
    Takaoka, T.: An O(1) time algorithm for generating multiset permutations. Lect. Notes Comp. Sci. 1741, 237–246 (1999)CrossRefMathSciNetGoogle Scholar
  14. 14.
    Trotter, H.F.: Algorithm 115, permutations. Comm. ACM 5, 434–435 (1962)CrossRefGoogle Scholar
  15. 15.
    Vajnovszki, V.: On the loopless generation of binary tree sequences. Inform. Process. Lett. 68, 113–117 (1998)CrossRefMathSciNetGoogle Scholar
  16. 16.
    Vajnovszki, V.: A loopless generation of bitstrings without p consecutive ones. In: Combinatorics, computability and logic, pp. 227–240. Springer Ser. Discrete Math. Theor. Comput. Sci. Springer, London (2001)Google Scholar
  17. 17.
    Vajnovszki, V.: A loopless algorithm for generating the permutations of a multiset. Theoret. Comput. Sci. 307, 415–431 (2003)MATHCrossRefMathSciNetGoogle Scholar
  18. 18.
    Walsh, T.: Loop-free sequencing of bounded integer compositions. J. Combin. Math. and Combin. Comput. 33, 323–345 (2000)MATHMathSciNetGoogle Scholar

Copyright information

© Springer Science+Business Media B.V. 2010

Authors and Affiliations

  1. 1.Department of MathematicsUniversity of HaifaHaifaIsrael

Personalised recommendations