maths.free › Combinatorics & Graph Theory › 8. Generating Functions › Generating Functions: exercises
Generating Functions: exercises
Generating Functions: exercises — from Keller & Trotter, Applied Combinatorics.
Practice (33)
Try each one on paper first. Reveal the answer to check; verified ones can be opened in the solver for every step.
-
For each finite sequence below, give its generating function.
\(1, 4, 6, 4, 1\)
\(1,1,1,1,1,0,0,1\)
\(0,0,0,1,2,3,4,5\)
\(1,1,1,1,1,1,1\)
\(3,0,0,1,-4,7\)
\(0,0,0,0,1,2,-3,0,1\)
-
For each infinite sequence suggested below, give its generating function in closed form, , not as an infinite sum. (Use the most obvious choice of form for the general term of each sequence.)
\(0,1,1,1,1,1,\dots\)
\(1,0,0,1,0,0,1,0,0,1,0,0,1,\dots\)
\(1,2,4,8,16,32,\dots\)
\(0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,\dots\)
\(1,-1,1,-1,1,-1,1,-1,1,-1,\dots\)
\(\displaystyle 2^8,2^7\binom{8}{1}, 2^6\binom{8}{2},\dots,\binom{8}{8},0,0,0,\dots\)
\(1,1,1,0,0,1,1,1,1,1,1,1,1,1,\dots\)
\(0,0,0,1,2,3,4,5,6,\dots\)
\(3,2,4,1,1,1,1,1,1,\dots\)
\(0,2,0,0,2,0,0,2,0,0,2,0,0,2,\dots\)
\(6,0,-6,0,6,0,-6,0,6,\dots\)
\(\displaystyle 1,3,6,10,15,\dots,\binom{n+2}{2},\dots\)
-
For each generating function below, give a closed form for the \(n^{\text{th} }\) term of its associated sequence.
\((1+x)^{10}\)
\(\displaystyle \frac{1}{1-x^4}\)
\(\displaystyle \frac{x^3}{1-x^4}\)
\(\displaystyle \frac{1-x^4}{1-x}\)
\(\displaystyle \frac{1+x^2-x^4}{1-x}\)
\(\displaystyle \frac{1}{1-4x}\)
\(\displaystyle \frac{1}{1+4x}\)
\(\displaystyle \frac{x^5}{(1-x)^4}\)
\(\displaystyle \frac{x^2+x+1}{1-x^7}\)
\(\displaystyle 3x^4 + 7x^3 -x^2 + 10 + \frac{1}{1-x^3}\)
-
Find the coefficient on \(x^{10}\) in each of the generating functions below.
\((x^3+x^5+x^6)(x^4+x^5+x^7) (1+x^5+x^{10}+x^{15}+\cdots)\)
\((1+x^3) (x^3+x^4+x^5+\cdots)(x^4+x^5+x^6+x^7+x^8+\cdots)\)
\((1+x)^{12}\)
\(\displaystyle\frac{x^5}{1-3x^5}\)
\(\displaystyle\frac{1}{(1-x)^3}\)
\(\displaystyle\frac{1}{1-5x^4}\)
\(\displaystyle\frac{x}{1-2x^3}\)
\(\displaystyle\frac{1-x^{14}}{1-x}\)
-
Find the generating function for the number of ways to create a bunch of \(n\) balloons selected from white, gold, and blue balloons so that the bunch contains at least one white balloon, at least one gold balloon, and at most two blue balloons. How many ways are there to create a bunch of \(10\) balloons subject to these requirements?
-
A volunteer coordinator has \(30\) identical chocolate chip cookies to distribute to six volunteers. Use a generating function (and computer algebra system) to determine the number of ways she can distribute the cookies so that each volunteer receives at least two cookies and no more than seven cookies.
-
Consider the inequality \[\begin{aligned}\end{aligned}\] where \(x_1,x_2,x_3,x_4,n\geq 0\) are all integers. Suppose also that \(x_2\geq 2\), \(x_3\) is a multiple of \(4\), and \(0\leq x_4\leq 3\). Let \(c_n\) be the number of solutions of the inequality subject to these restrictions. Find the generating function for the sequence \(\{c_n\colon n\geq 0\}\) and use it to find a closed formula for \(c_n\).
Reveal the answer
Because of the inequality, it is easier to count here in the setting where we have \(x_{1}+x_{2}+x_{3}+x_{4}+x_{5} = n\) and \(x_{5}\geq 0\) is an integer along with all the constraints laid out in the exercise. Since there is no constraint on \(x_{1}\) or \(x_{5}\) other than that they are nonnegative integers, the generating function contains a factor of \(1/(1-x)\) for each of these variables. For \(x_{2}\), we have \(x^{2}/(1-x)\) to ensure that \(x_{2}\geq 2\). For \(x_{3}\) to be a multiple of \(4\), the generating function includes \(1/(1-x^{4})\). To have \(0\leq x_{4}\leq 3\), we end up with \(1+x+x^{2}+x^{3}\) in the generating function. Thus, the generating function is \[\begin{aligned}\end{aligned}\]. This generating function simplifies (by factoring \(1-x^{4}\)) to be \(x^{2}/(1-x)^{4}\). Noting that \(1/(1-x)^{4}\) is \(1/6\) times the third derivative of \(1/(1-x)\), we have \[\begin{aligned}\end{aligned}\] and therefore, we have \(c_{n}=\frac{n(n^{2}-1)}{6}\).
-
Find the generating function for the number of ways to distribute blank scratch paper to Alice, Bob, Carlos, and Dave so that Alice gets at least two sheets, Bob gets at most three sheets, the number of sheets Carlos receives is a multiple of three, and Dave gets at least one sheet but no more than six sheets of scratch paper. Without finding the power series expansion for this generating function (or using a computer algebra system!), determine the coefficients on \(x^2\) and \(x^3\) in this generating function.
-
What is the generating function for the number of ways to select a group of \(n\) students from a class of \(p\) students?
-
Using generating functions, find a formula for the number of different types of fruit baskets containing of \(n\) pieces of fruit chosen from pomegranates, bananas, apples, oranges, pears, and figs that can be made subject to the following restrictions:
- \(0\)\(2\)
- \(1\)
- \(5\)
- \(4\)
- there are no restrictions on the number of apples or oranges.
-
Using generating functions, find the number of ways to make change for a \(100\) dollar bill using only dollar coins and $\(1\), $\(2\), and $\(5\) bills.
Reveal the answer
Hint:
Find the partial fractions expansion for your generating function. Be careful here, as you want a partial fraction expansion in which all coefficients for your denominator polynomials have integer coefficients. The
partial_fraction()method in SageMath should be useful here, andpretty_printwill make it easier to read. Once you have the right partial fractions expansion, you may find the following identity helpful \[\begin{aligned}\end{aligned}\] where \(p(x)\) will be a polynomial in this instance. -
A businesswoman is traveling in Belgium and wants to buy chocolates for herself, her husband, and their two daughters. A store has dark chocolate truffles (€10/box), milk chocolate truffles (€8/box), nougat-filled chocolates (€5/box), milk chocolate bars (€7/bar), and 75% cacao chocolate bars (€11/bar). Her purchase is to be subject to the following:
Only the daughters like dark chocolate truffles, and her purchase must ensure that each daughter gets an equal number of boxes of them (if they get any).
At least two boxes of milk chocolate truffles must be purchased.
If she buys any boxes of nougat-filled chocolates, then she buys exactly enough that each family member gets precisely one box of them.
At most three milk chocolate bars may be purchased.
There are no restrictions on the number of 75% cacao chocolate bars.
Reveal the answer
The first constraint means we need an even number of boxes of dark chocolate truffles, so we must spend a multiple of €20 on dark chocolate truffles. This contributes a factor of \(1/(1-x^{20})\) to the generating function. Since milk chocolate truffles are €8 per box, we must spend a multiple of 8 that is at least 16 (for two boxes) on milk chocolate truffles. This contributes a factor of \(x^{16}/(1-x^{8})\) to the generating function. For nougat-filled chocolates, she will buy either 0 boxes or 4 boxes, meaning she will spend either €0 or €20. The generating function thus includes \(1+x^{20}\). For milk chocolate bars, since we buy at most 3 at €7/bar, the generating function must include \(1+x^{7}+x^{14}+x^{21}\). Finally, for the 75 \[\begin{aligned}\end{aligned}\]. Putting this into SageMath, we find that \(s_{100}= 16\), so there are \(16\) ways for her to spend €100.
-
Make up a combinatorial problem (similar to those found in this chapter) that leads to the generating function \[\begin{aligned}\end{aligned}\]
-
List the partitions of \(9\). Write a D next to each partition into distinct parts and an O next to each partition into odd parts.
-
Use generating functions to find the number of ways to partition \(10\) into odd parts.
-
What is the smallest integer that can be partitioned in at least \(1000\) ways? How many ways can it be partitioned? How many of them are into distinct parts? (A computer algebra system will be helpful for this exercise.)
-
What is the generating function for the number of partitions of an integer into even parts?
-
Find the exponential generating function (in closed form, not as an infinite sum) for each infinite sequence \(\{a_n\colon n\geq 0\}\) whose general term is given below.
\(a_n = 5^n\)
\(a_n = (-1)^n2^n\)
\(a_n = 3^{n+2}\)
\(a_n = n!\)
\(a_n = n\)
\(a_n = 1/(n+1)\)
-
For each exponential generating function below, give a formula in closed form for the sequence \(\{a_n\colon n\geq 0\}\) it represents.
\(e^{7x}\)
\(x^2 e^{3x}\)
\(\displaystyle \frac{1}{1+x}\)
\(e^{x^4}\)
-
Find the coefficient on \(x^{10}/{10!}\) in each of the exponential generating functions below.
\(e^{3x}\)
\(\displaystyle\frac{e^x-e^{-x}}{2}\)
\(\displaystyle\frac{e^x+e^{-x}}{2}\)
\(xe^{3x}-x^2\)
\(\displaystyle\frac{1}{1-2x}\)
\(e^{x^2}\)
-
Find the exponential generating function for the number of strings of length \(n\) formed from the set \(\{a,b,c,d\}\) if there must be at least one \(a\) and the number of \(c\)'s must be even. Find a closed formula for the coefficients of this exponential generating function.
-
Find the exponential generating function for the number of strings of length \(n\) formed from the set \(\{a,b,c,d\}\) if there must be at least one \(a\) and the number of \(c\)'s must be odd. Find a closed formula for the coefficients of this exponential generating function.
-
Find the exponential generating function for the number of strings of length \(n\) formed from the set \(\{a,b,c,d\}\) if there must be at least one \(a\), the number of \(b\)'s must be odd, and the number of \(d\)'s is either \(1\) or \(2\). Find a closed formula for the coefficients of this exponential generating function.
-
Find the exponential generating function for the number of alphanumeric strings of length \(n\) formed from the \(26\) uppercase letters of the English alphabet and \(10\) decimal digits if
each vowel must appear at least one time;
the letter \(T\) must appear at least three times;
the letter \(Z\) may appear at most three times;
each even digit must appear an even number of times; and
each odd digit must appear an odd number of times.
-
Consider the inequality \[\begin{aligned}\end{aligned}\] where \(x_1,x_2,x_3,x_4,n\geq 0\) are all integers. Suppose also that \(x_2\geq 2\), \(x_3\) is a multiple of \(4\), and \(1\leq x_4\leq 3\). Let \(c_n\) be the number of solutions of the inequality subject to these restrictions. Find the generating function for the sequence \(\{c_n\colon n\geq 0\}\) and use it to find a closed formula for \(c_n\).
Reveal the answer
Hint:
Yes, this is very close to . However, the bounds on \(x_4\) are different here. You might try using a computer algebra system to expedite finding the partial fractions expansion, which will have several terms whose power series you can work with quickly. For the term involving \(1/(1+x^2)\), work out the series by hand. You may find that your solution to this problem has two partsone for when \(n\) is even and another for when \(n\) is odd.
-
Prove about the coefficients in the product of two ordinary generating functions.
-
Suppose you wanted to make a really boring fruit basket that contains only apples. Let's also say that you have only \(6\) (identical) apples available. For aesthetic reasons, you insist that the basket contain exactly \(1\), \(3\), or \(4\) apples.
In how many ways (the apples are identical!) can you make a single fruit basket with one apple?
-
Suppose you wanted to make a really boring fruit basket that contains only apples. Let's also say that you have only \(6\) (identical) apples available. For aesthetic reasons, you insist that the basket contain exactly \(1\), \(3\), or \(4\) apples.
In how many ways (the apples are identical!) can you make a single fruit basket with five apples?
-
We already know that if we are making a fruit basket with 1, 3, or 4 apples and at most 6 oranges, the generating function would be \[\begin{aligned}\end{aligned}\]. Suppose we now have bananas to add and that we must place at least one banana in a fruit basket. This introduces which factor?
-
If a fruit basket generating function contains a factor that is a polynomial, you know
-
Based on the class prep, which of the following statements do you think are reasonably accurate?
-
Suppose we are making strings using the alphabet \(\{0,1,2,3,4\}\). If the number of times \(4\) appears in the string is at least one and at most four, what factor would be included in a generating function to account for this restriction?
-
Suppose we are making strings using the alphabet \(\{0,1,2,3,4\}\). If the number of times \(2\) appears in the string is a positive even number, what factor would be included in a generating function to account for this restriction?
Symbols used here
Number of k-element subsets of n things: n!/(k!(n−k)!).
n × (n−1) × … × 1; the number of orderings of n things. 0! = 1.
2.71828…, the base whose exponential is its own derivative.
Inequalities that allow equality; < and > exclude it.
Add a_k for k = 1 up to n.
Multiply a_k for k = 1 up to n.
The set with no elements; the number of elements of A.
Questions people ask
Permutation or combination?
Ask whether order matters. A lock code is a permutation (order matters); a hand of cards is a combination (it does not).
What is a graph in this sense?
Dots (vertices) joined by lines (edges) — not a plot. Road maps, social networks and molecules are graphs; questions like "is there a route" and "how few colours" are graph theory.
Try your own
Parts of this page are adapted from Keller & Trotter, Applied Combinatorics (CC BY-SA 4.0). Condensed and re-explained here; errors are ours.
More in Combinatorics & Graph Theory
The counting principlesPigeonhole principle and inclusion–exclusionBinomial coefficients and Pascal's triangleRecurrences and generating functionsGraphs: vertices, edges, degreesPaths, cycles, trees, Euler and HamiltonColouring and planar graphs