Springer Nature is making SARS-CoV-2 and COVID-19 research free. View research | View latest news | Sign up for updates

Generalized Algorithm for Restricted Weak Composition Generation

Generation Algorithm for Second-Order Restricted Weak Compositions


This paper presents a new algorithm that arrives at a generalized solution for the generation of restricted weak compositions of n-parts. In particular, this generalized algorithm covers many commonly sought compositions such as bounded compositions, restricted compositions, weak compositions, and restricted part compositions. Introduced is an algorithm for generating generalized types of restricted weak compositions called first-order, and second-order restricted weak compositions.

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


  1. 1.

    Bacchelli, S., Barcucci, E., Grazzini, E., Pergola, E.: Exhaustive generation of combinatorial objects by eco. Acta Inform. 40, 585–602 (2004)

  2. 2.

    Bernini, A., Grazzini, E., Pergola, E., Pinzani, R.: A general exhaustive generation algorithm for gray structures. Acta Inform. 44, 361–376 (2007)

  3. 3.

    Gray, F.: Pulse code communication. US Patent 2632058 (1953)

  4. 4.

    Heubach, S., Mansour, T.: Combinatorics of Compositions and Words. CRC Press (2010)

  5. 5.

    Klingsberg, P.: A gray code for compositions. J. Algorithms 3(1), 41–44 (1981)

  6. 6.

    Knuth, D.: The Art of Computer Programming, vol. 4. Addison Wesley (2005)

  7. 7.

    Mansour, T., Nassar, G.: Gray codes, loopless algorithm and partitions. J. Math. Model. Algor. 7, 291–310 (2008)

  8. 8.

    Mansour, T., Nassar, G.: Loop-free gray code algorithms for the set of compositions. J. Math. Model. Algor. 9, 343–345 (2010)

  9. 9.

    Opdyke, J.: A unified approach to algorithms generating unrestricted and restricted integer compositions and integer partitions. Journal of Mathematical Modelling and Algorithms 9(1), 53–97 (2010)

  10. 10.

    Reingold, E.M., Nievergelt, J., Deo, N.: Combinatorial algorithms: theory and practice. Prentice-Hall Inc. (1977)

  11. 11.

    Vajnovszki, V., Vernay, R.: Restricted compositions and permutations: from old to new gray codes. Inf. Process. Lett. 111(13), 650–655 (2011)

  12. 12.

    Walsh, T.: Loop-free sequencing of bounded integer compositions. J. Comb. Math. Comb. Comput. 33, 323–345 (2000)

  13. 13.

    Walsh, T.: Generating gray codes in o(1) worse-case time per word. Discret. Math. Theor. Comput. Sci. 2731, 73–88 (2003)

Download references

Author information

Correspondence to Daniel R. Page.

Rights and permissions

Reprints and Permissions

About this article

Cite this article

Page, D.R. Generalized Algorithm for Restricted Weak Composition Generation. J Math Model Algor 12, 345–372 (2013).

Download citation


  • Restricted compositions
  • Restricted weak compositions
  • Generalized algorithms
  • Generalized compositions
  • Generation algorithms
  • Enumeration algorithms
  • Integer compositions
  • Weak integer compositions
  • Enumeration
  • Combinatorics
  • Computational number theory

Mathematics Subject Classifications (2010)

  • 68R05
  • 68R01