Gray Codes, Loopless Algorithm and Partitions



The generation of efficient Gray codes and combinatorial algorithms that list all the members of a combinatorial object has received a lot of attention in the last few years. Knuth gave a code for the set of all partitions of [n] = {1,2,...,n}. Ruskey presented a modified version of Knuth’s algorithm with distance 2. Ehrlich introduced a looplees algorithm for the set of the partitions of [n]; Ruskey and Savage generalized Ehrlich’s results and introduced two Gray codes for the set of partitions of [n]. In this paper, we give another combinatorial Gray code for the set of the partitions of [n] which differs from the aforementioned Gray codes. Also, we construct a different loopless algorithm for generating the set of all partitions of [n] which gives a constant time between successive partitions in the construction process.


Gray codes Loopless algorithms Partitions Plane trees 

Mathematics Subject Classifications (2000)

Primary: 05A05 94B25; Secondary: 05A15 


  1. 1.
    Baril, J.-L.: Gray code for permutations with a fixed number of cycles. Disc. Math. 307(13), 1559–1571 (2007)MATHCrossRefMathSciNetGoogle Scholar
  2. 2.
    Baril, J.-L., Vajnovszki, V.: Gray code for derangements. Discrete Appl. Math. 140, 207–221 (2004)MATHCrossRefMathSciNetGoogle Scholar
  3. 3.
    Ehrlich, G.: Loopless algorithms for generating permutations, combinations, and other combinatorial configurations. J. Assoc. Comput. Mach. 20, 500–513 (1973)MATHMathSciNetGoogle Scholar
  4. 4.
    Johson, S.M.: Generating of permutations by adjacent transposition. Math. Comput. 17, 282–285 (1963)CrossRefGoogle Scholar
  5. 5.
    Klazar, M.: On abab-free and abba-free set partitions. Eur. J. Comb. 17, 53–68 (1996)MATHCrossRefMathSciNetGoogle Scholar
  6. 6.
    Ko, C.W., Ruskey, F.: Generating permutations of a bag by interchanges. Inf. Process. Lett. 41, 263–269 (1992)MATHCrossRefMathSciNetGoogle Scholar
  7. 7.
    Korsh, J.F., LaFollette, P.S.: Loopless array generation of multiset permutations. Technical Report, Department of CIS, PA, USA (2002)Google Scholar
  8. 8.
    Korsh, J.F., Lipschutz, S.: Generating multiset permutations in constant time. J. Algorithms 25, 321–335 (1997)MATHCrossRefMathSciNetGoogle Scholar
  9. 9.
    Roelants van Baronaigien, D., Ruskey, F.: Generating permutations with given ups and downs. Disc. Appl. Math. 36(1), 57–65 (1992)MATHCrossRefMathSciNetGoogle Scholar
  10. 10.
  11. 11.
    Ruskey, F., Savage, C.D.: Gray codes for set partitions and restricted growth tails. Aust. J. Combin. 10, 85–96 (1994)MATHMathSciNetGoogle Scholar
  12. 12.
    Stanley, R.: Enumerative Combinatorics, vol. 1. Cambridge University Press, Cambridge, UK (1997)MATHGoogle Scholar
  13. 13s.
    Stanton, D., White, D.: Constructive Combinatorics. Springer-Verlag, Berlin Heidelberg New York (1986)MATHGoogle Scholar
  14. 14.
    Takaoka, T., An O(1) time algorithm for generating multiset permutations. Lect. Notes Comput. Sci. 1741, 237–246 (1999)CrossRefMathSciNetGoogle Scholar
  15. 15.
    Trotter, H.F.: Algorithm 115, permutations. Commun. ACM 5, 434–435 (1962)CrossRefGoogle Scholar
  16. 16.
    Vajnovszki, V.: A loopless algorithm for generating the permutations of a multiset. Theor. Comput. Sci. 307, 415–431 (2003)MATHCrossRefMathSciNetGoogle Scholar
  17. 17.
    Walsh, T.: Gray codes for involutions. J. Combin. Math. Combin. Comput. 36, 95–118 (2001)MATHMathSciNetGoogle Scholar

Copyright information

© Springer Science+Business Media B.V. 2008

Authors and Affiliations

  1. 1.Department of MathematicsUniversity of HaifaHaifaIsrael

Personalised recommendations