# A Unified Approach to Algorithms Generating Unrestricted and Restricted Integer Compositions and Integer Partitions

• John Douglas (J.D.) Opdyke
Article

## Abstract

An original algorithm is presented that generates both restricted integer compositions and restricted integer partitions that can be constrained simultaneously by (a) upper and lower bounds on the number of summands (“parts”) allowed, and (b) upper and lower bounds on the values of those parts. The algorithm can implement each constraint individually, or no constraints to generate unrestricted sets of integer compositions or partitions. The algorithm is recursive, based directly on very fundamental mathematical constructs, and given its generality, reasonably fast with good time complexity. A general, closed form solution to the open problem of counting the number of integer compositions doubly restricted in this manner also is presented; its formulaic link to an analogous solution for counting doubly-restricted integer partitions is shown to mirror the algorithmic link between these two objects.

## Keywords

Integer compositions Integer partitions Bounded compositions Bounded partitions Pascal’s triangle Fibonacci

## Mathematics Subject Classifications (2000)

05A07 11P82 11Y16 11Y55

## References

1. 1.
Andrews, G.: The Theory of Partitions. Cambridge University Press, Cambridge (1998)
2. 2.
Beyer, T., Swinehart, D.: Algorithm 448: number of multiply-restricted partitions. Commun. ACM 16(7), 379 (1973)
3. 3.
Chinn, P., Heubach, S.: Compositions of n with no occurrence of k. Congressus Numerantium 164, 33–51 (2003)
4. 4.
Ehrlich, G.: Loopless algorithms for generating permutations, combinations, and other combinatorial configurations. J. ACM 20, 500–513 (1973)
5. 5.
Grimaldi, R.: Compositions without the summand 1. Congressus Numerantium 152, 33–43 (2001)
6. 6.
Heubach, S., Mansour, T.: Compositions of n with parts in a set. Congressus Numerantium 168, 127–143 (2004)
7. 7.
Kimberling, C.: Enumeration of paths, compositions of integers, and Fibonacci numbers. Fibonacci Q. 39(6) (2001)Google Scholar
8. 8.
Kimberling, C.: Path-counting and Fibonacci numbers. Fibonacci Q. 40(4) (2002)Google Scholar
9. 9.
Klingsberg, P.: A gray code for compositions. J. Algorithms 3, 41–44 (1982)
10. 10.
Koepf, W.: Hypergeometric Summation: An Algorithmic Approach to Summation and Special Function Identities. Vieweg, Braunschweig (1998)
11. 11.
Knuth, D., Szwarcfiter, J.: A structured program to generate all topological sorting arrangements. Inf. Process. Lett. 2, 153–157 (1974)
12. 12.
Knuth, D.: The Stanford Graphbase. ACM, New York (1994)
13. 13.
14. 14.
Ruskey, F.: Combinatorial Generation. Working Version (1j-CSC 425/520) (2003)Google Scholar
15. 15.
Sanchis, L., Squire, M.: Parallel algorithms for counting and randomly generating integer partitions. J. Parallel Distrib. Comput. 34(1), 29–35 (1996)
16. 16.
Sloan, N.J.A. (ed.): The online encyclopedia of integer sequences. http://www.research.att.com/~njas/sequences (2008)
17. 17.
Stojmenovic, I.: Generating all and random instances of a combinatorial object. In: Nayak, A., Stojmenovic, I. (eds.) Handbook of Applied Algorithms: Solving Scientific, Engineering and Practical Problems. Wiley, New York (2008)Google Scholar
18. 18.
Uppuluri, V., Carpenter, J.: A problem of restricted partitions. Nav. Res. Logist. Q. 21(1), 201–205 (2006)
19. 19.
Walsh, T.: Loop-free sequencing of bounded integer compositions. J. Comb. Math. Comb. Comput. 33, 323–345 (2000)
20. 20.
White, J.: Algorithm 373: number of doubly restricted partitions[A1]. Commun. ACM 13(2), 120 (1970)
21. 21.
White, J.: Algorithm 374: restricted partition generator[A1]. Commun. ACM 13(2), 120 (1970)
22. 22.
Yamanaka, K., et al.: Constant time generation of integer partitions. IEICE Trans. Fundam. E90-A(6) (2007)Google Scholar
23. 23.
Zoghbi, A., Stojmenovic, I.: Fast algorithms for generating integer partitions. Int. J. Comput. Math. 70, 319–332 (1998)