MGU Mathematics Series — Discrete Mathematics
Part III: Counting, Probability, and Combinatorics
Pigeonhole · Stars and Bars · Recurrences · Combinatorial Proof
Chapter 9 of 14
MGU Mathematics Series  ·  Discrete Mathematics  ·  Library Textbook Edition

Chapter 9:
Advanced Counting
and Combinatorial Reasoning

The pigeonhole principle, combinations with repetition, stars and bars, integer solutions, partitions, recurrence relations, and combinatorial proof — the tools that count structure too large to list

■ Math Level: Discrete Mathematics ■

■ 14 Sections  •  Part III of 5 ■

Follows Chapter 8: Permutations, Combinations, and Discrete Probability  ·  Prepares students for Chapter 10: Graph Theory Foundations

Purpose and Overview

Chapter 8 introduced the fundamental tools of combinatorics: permutations, combinations, factorials, and counting-based probability. Those tools answer many questions precisely and efficiently. But some counting problems resist these approaches. They involve distributions, repetition, structural constraints, or patterns that repeat in a predictable way. Chapter 9 extends the counting toolkit into these more sophisticated situations.

This chapter develops the pigeonhole principle, which proves that certain arrangements must exist even without constructing them; combinations with repetition and the stars and bars method, which count selections from categories when items may be reused; integer solutions to equations, a powerful reframing of distribution problems; introductory partition theory, which studies the ways to break a number into parts; and recurrence relations, which define counting sequences by their own patterns.

The chapter closes with combinatorial identities and combinatorial proofs, which are a distinctive kind of argument that explains why counting formulas are true rather than simply verifying them algebraically.

Advanced counting is not about memorizing more formulas. It is about understanding the structure of a problem clearly enough to choose the right representation. The strategies in this chapter will prepare students for algorithm analysis, data structures, probability theory, cryptography, and theoretical computer science.

Opening Question

Suppose a company assigns each employee a four-digit personal identification number using the digits 0 through 9. The company has 10,000 employees. Is it possible that two employees share the same PIN? At first, it might seem like there should be enough PINs to go around — after all, four-digit codes from 0000 to 9999 give exactly 10,000 possibilities. But what if the company uses only three-digit PINs? Then there are only 1,000 possible codes for 10,000 employees, and the answer becomes clear: some employees must share a PIN. But can we prove this without checking every assignment? This question — and the elegant principle that answers it — opens this chapter.

Why This Chapter Matters

Counting appears throughout mathematics and computer science, but the problems that arise in real applications are rarely as clean as "how many ways can five students sit in five chairs?" More commonly, the question involves resources distributed among categories, patterns in sequences, or overlapping constraints.

The techniques in this chapter appear in algorithm analysis, where recurrence relations describe how the running time of a recursive program grows; in database design, where counting distinct records with repeated categories matters for storage and performance; in cryptography, where the number of valid key distributions affects security analysis; in scheduling and resource allocation, where distributing identical tasks among workers is a combinations-with-repetition problem; and in data science, where feature selection and partitioning of data sets rely on advanced combinatorial reasoning.

Understanding these methods deeply — not as formulas to apply, but as ideas to think with — gives students a foundation for nearly every quantitative field.

14Sections
12Objectives
17Key Terms
15+Worked Examples & Proofs

Learning Objectives

  1. 1State and apply the pigeonhole principle to prove existence results.
  2. 2Apply the generalized pigeonhole principle to count guaranteed collisions.
  3. 3Distinguish between combinations without repetition and combinations with repetition.
  4. 4Use the stars and bars method to count non-negative integer solutions to equations.
  5. 5Count positive integer solutions by substitution and reframing.
  6. 6Describe what a partition of an integer is and compute small partition counts.
  7. 7Define a recurrence relation and identify base cases and recursive rules.
  8. 8Solve simple linear recurrences by substitution, unwinding, and pattern recognition.
  9. 9Recognize divide-and-conquer recurrences and interpret their growth behavior.
  10. 10State and verify standard combinatorial identities including Pascal's identity and the Vandermonde identity.
  11. 11Write a combinatorial proof by constructing a counting argument from both sides.
  12. 12Identify and correct common advanced counting mistakes.

Key Terms

pigeonhole principle
If more objects are placed into fewer containers than there are objects, at least one container holds more than one object.
generalized pigeonhole principle
If \(n\) objects are placed in \(k\) containers, at least one container holds at least \(\lceil n/k \rceil\) objects.
ceiling function
The ceiling of a real number \(x\), written \(\lceil x \rceil\), is the smallest integer greater than or equal to \(x\).
combinations with repetition
Selections of \(r\) items from \(n\) categories where items may be selected more than once.
stars and bars
A counting method that represents repetition-allowed selections as arrangements of stars and dividing bars.
non-negative integer solution
A solution to an equation in which all variables are integers greater than or equal to zero.
positive integer solution
A solution to an equation in which all variables are integers greater than or equal to one.
partition of an integer
A way of writing a positive integer as an unordered sum of positive integers.
recurrence relation
A rule that defines each term of a sequence in terms of previous terms, together with one or more base cases.
homogeneous linear recurrence
A recurrence in which each term is a linear combination of previous terms with no constant term added.
characteristic equation
An algebraic equation derived from a recurrence relation whose roots determine the closed form of the sequence.
closed form
A direct formula for the \(n\)-th term of a sequence that does not require computing all earlier terms.
combinatorial identity
An equation involving binomial coefficients that holds for all valid values of the parameters.
combinatorial proof
A proof that an identity is true by showing that both sides count the same collection in two different ways.
double counting
A proof technique that counts a set by two different methods and equates the results.
divide-and-conquer recurrence
A recurrence relation describing the running time of an algorithm that splits a problem into smaller subproblems.
base case
A starting value of a recurrence relation from which all later terms are computed.

Sections at a Glance

Sections 9.1 – 9.3
Existence Without Construction: The Pigeonhole Principle
Why Advanced Counting Matters · The Pigeonhole Principle · Generalized Pigeonhole Principle

Why Advanced Counting Matters

The counting methods from Chapters 7 and 8 answer a wide range of questions. The multiplication principle counts sequential independent choices. Permutations count ordered arrangements. Combinations count unordered selections. Inclusion-exclusion counts overlapping collections.

But some counting problems have structures these tools alone cannot handle cleanly. Consider four examples that illustrate the kinds of problems this chapter is built to solve.

Problem TypeDescriptionExample
Distributions with repetitionItems from the same category may be chosen more than onceA bookstore sells five genres. A customer buys four books, possibly several from one genre. How many selections are possible?
Existence without constructionA guaranteed outcome can be proved without listing every caseFifty students take a test scored 0–100. Must two students share a score?
Recursive growthA quantity is defined in terms of smaller versions of itselfA sorting algorithm splits a list in half, sorts each half, and merges. How many operations does it take?
Identity verificationA formula is shown to be true by what it counts, not just by algebraWhy is \(\binom{n}{r} = \binom{n-1}{r-1} + \binom{n-1}{r}\)?

Each of these problem types requires a different extension of the counting toolkit. The first is addressed by combinations with repetition and the stars and bars method (Sections 9.4–9.6). The second is addressed by the pigeonhole principle (Sections 9.2–9.3). The third is addressed by recurrence relations (Sections 9.8–9.10). The fourth is addressed by combinatorial identities and combinatorial proofs (Sections 9.11–9.12).

Section by section, this chapter builds these extensions. By the end, you will have a broader and more flexible view of what counting can do — and, just as importantly, a clearer sense of when each tool applies.

Practice 9.1Concept Check
  1. In your own words, explain why the standard combination formula \(\binom{n}{r}\) is not enough to count selections where repetition is allowed.
  2. Give an everyday example (not from the table above) of a situation where you suspect "two things must match" but cannot easily check every case.
  3. Why might a formula that is true be hard to *believe* just by looking at it — and what kind of argument might make it easier to believe?

The Pigeonhole Principle

The Core Idea

Imagine twelve pigeons returning to a coop that has only eleven holes. No matter how the pigeons arrange themselves, at least one hole must contain at least two pigeons. This observation — obvious in the physical setting — becomes a powerful mathematical tool when stated precisely.

Pigeonhole Principle

If \(n+1\) or more objects are distributed into \(n\) containers, then at least one container must contain at least two objects.

More generally: if more objects are placed into containers than there are containers, some container must hold more than one object.

The principle does not tell us which container holds more than one object. It does not tell us how many objects that container holds. It only guarantees that the overcrowded situation must occur. This makes the pigeonhole principle an existence theorem — it proves that something exists without constructing it.

Applying the Principle

To use the pigeonhole principle, identify the objects being distributed, the containers receiving them, and explain why the number of objects exceeds the number of containers. Then conclude that some container holds at least two objects.

Example 9.2.1
Shared Birthday Month
  • ProblemA club has thirteen members. Must at least two members share a birthday month?
  • ThinkThere are thirteen members (objects) and twelve months (containers). Since \(13 > 12\), the pigeonhole principle applies.
  • SolveAssign each member to the container corresponding to their birthday month. Since there are thirteen members and only twelve months, by the pigeonhole principle, at least one month must contain at least two members.
  • CheckThe conclusion is a guarantee, not a coincidence. No matter how the birthdays are assigned, the arithmetic forces the overlap.
Answer: Yes. With thirteen members and twelve months, at least two members must share a birthday month.
Example 9.2.2
Repeated Remainder
  • ProblemProve that among any thirteen integers, at least two must have the same remainder when divided by 12.
  • ThinkThe remainder when divided by 12 is always one of the values \(\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\}\). That gives twelve possible containers.
  • SolveAssign each integer to the container labeled by its remainder mod 12. With thirteen integers and twelve containers, the pigeonhole principle guarantees that at least one container holds at least two integers.
  • CheckTwo integers with the same remainder when divided by 12 differ by a multiple of 12. The conclusion is purely structural — it holds for any choice of thirteen integers.
Answer: Among any thirteen integers, at least two have the same remainder modulo 12.
Example 9.2.3
Socks in a Drawer
  • ProblemA drawer contains red, blue, and green socks. How many socks must be drawn at random (without looking) to guarantee that at least two socks of the same color have been selected?
  • ThinkEach sock drawn goes into one of three color categories. To guarantee a match, find the minimum number of draws so that some category must contain two.
  • SolveWith three colors, it is possible to draw one of each color — three socks — and still have no matching pair. But the moment a fourth sock is drawn, there are four socks in three categories, and by the pigeonhole principle, at least one category must contain two.
Answer: Four socks must be drawn to guarantee a matching pair.
Student Note

The pigeonhole principle gives a minimum guarantee. In real applications, matching pairs might appear earlier. But we need to guarantee the outcome regardless of luck, so we must plan for the worst case.

Practice 9.2Pigeonhole Reasoning
  1. A drawer contains gloves in 4 colors. How many gloves must be drawn to guarantee a matching pair?
  2. Explain why, in any group of 8 people, at least two must have been born on the same day of the week.
  3. A bag contains tiles numbered with the digits 0 through 9 (one tile per digit). If 11 tiles are drawn with replacement (the tile is returned after each draw), must some digit be drawn at least twice? Explain.
  4. A teacher has 5 different colored pens and 6 students. Each student is given exactly one pen color (colors may repeat). Must two students have the same pen color? Justify your answer using the pigeonhole principle.

Generalized Pigeonhole Principle

Guaranteeing More Than Two

The basic pigeonhole principle guarantees at least one container holds at least two objects. The generalized version tells us more precisely how full at least one container must be.

Generalized Pigeonhole Principle

If \(n\) objects are distributed into \(k\) containers, then at least one container holds at least \(\left\lceil \dfrac{n}{k} \right\rceil\) objects.

The symbol \(\lceil x \rceil\) denotes the ceiling of \(x\) — the smallest integer greater than or equal to \(x\). For example, \(\lceil 7/3 \rceil = \lceil 2.33\ldots \rceil = 3\).

Why the Ceiling Appears

Suppose 10 objects are placed in 3 containers. Is it possible that every container holds at most 3 objects? If each holds at most 3, the total is at most \(3 \times 3 = 9\) — but there are 10 objects. Contradiction. So at least one container must hold at least 4. And indeed \(\lceil 10/3 \rceil = \lceil 3.33\ldots \rceil = 4\).

The ceiling function captures the smallest integer large enough to force the overcrowding.

Example 9.3.1
Guaranteed Repeats in a Sequence
  • ProblemA sequence of 25 integers is drawn from \(\{1, 2, 3, 4, 5, 6, 7\}\). What is the minimum number of times some value must appear?
  • ThinkThere are 25 objects (integers in the sequence) and 7 containers (possible values). Apply the generalized pigeonhole principle.
  • Solve ⌈25/7⌉ = ⌈3.571...⌉ = 4 At least one value must appear at least 4 times.
  • CheckIf every value appeared at most 3 times, the sequence would contain at most \(7 \times 3 = 21\) integers, fewer than 25. So at least one value must appear at least 4 times.
Answer: At least one value appears at least 4 times.
Example 9.3.2
Cards from a Standard Deck
  • ProblemHow many cards must be drawn from a standard 52-card deck (without replacement) to guarantee that at least 5 cards of the same suit have been selected?
  • ThinkThere are four suits (clubs, diamonds, hearts, spades). We want to guarantee that at least one suit has 5 cards selected. Use the worst case: each suit can have at most 4 cards before the guarantee is forced.
  • SolveIn the worst case, we draw 4 cards from each suit before drawing a fifth from any suit. That is \(4 \times 4 = 16\) cards. The next card — the 17th — must come from some suit that already has 4 cards selected, giving that suit 5.
Answer: 17 cards must be drawn to guarantee at least 5 cards from the same suit.
Student Note — Worst-Case Thinking

When answering "how many must be drawn to guarantee some condition," always think about the worst case — the maximum number of draws where the condition might not yet hold — and then add one.

Practice 9.3Generalized Pigeonhole Practice
  1. A sequence of 50 integers is drawn from \(\{1, 2, \ldots, 6\}\). What is the minimum number of times some value must appear?
  2. How many cards must be drawn from a standard 52-card deck to guarantee at least 3 cards of the same suit?
  3. A factory produces items in 9 color categories. How many items must roll off the line to guarantee that at least 5 items share a color?
  4. Explain, using a worst-case argument, why \(\lceil n/k \rceil\) — and not \(n/k\) rounded down — is the correct guaranteed minimum.
Sections 9.4 – 9.7
Counting Selections with Repetition
Combinations with Repetition · Stars and Bars · Integer Solutions · Partitions

Combinations with Repetition

What Changes When Repetition Is Allowed

In Chapter 8, a combination counted the number of ways to choose \(r\) objects from \(n\) distinct objects without replacement. Each object could be chosen at most once, and order did not matter. The formula was:

Recall — Standard Combination

$$\binom{n}{r} = \frac{n!}{r!(n-r)!}$$

Now suppose repetition is allowed: each object may be selected more than once, and order still does not matter. This is the problem of combinations with repetition, also called multiset coefficients.

For example, suppose a café sells coffee, tea, and juice. A customer orders 4 drinks. Order does not matter; only the count of each type matters. How many selections are possible? The customer might order 4 coffees, or 2 coffees and 2 teas, or 1 of each plus 1 extra coffee, and so on. This is a selection with repetition from 3 categories.

The Formula for Combinations with Repetition

Combinations with Repetition

The number of ways to choose \(r\) items from \(n\) categories (with repetition allowed, order unimportant) is:

$$\binom{n + r - 1}{r}$$

This formula will be derived carefully in Section 9.5 using stars and bars. For now, note how it works. For the café example, \(n = 3\) categories and \(r = 4\) drinks:

⎛3 + 4 − 1⎞ ⎛6⎞ ⎝ 4 ⎠ = ⎝4⎠ = 15
Example 9.4.1
Counting Drink Orders
  • ProblemA café sells coffee, tea, and juice. A customer orders 4 drinks. How many different orders are possible (considering only counts of each type, not the sequence in which they are served)?
  • ThinkThis is a combinations-with-repetition problem: selecting 4 items from 3 categories with repetition allowed.
  • Solve $$\binom{3 + 4 - 1}{4} = \binom{6}{4} = \frac{6!}{4!\cdot 2!} = \frac{6 \times 5}{2} = 15$$
Answer: There are 15 different drink orders.
Example 9.4.2
Distributing Identical Items into Boxes
  • ProblemIn how many ways can 7 identical apples be distributed among 4 children?
  • ThinkBecause the apples are identical, what matters is how many each child receives. Each child can receive 0 or more apples. This is a combinations-with-repetition problem: choosing 7 apples from 4 children (categories) with repetition.
  • Solve $$\binom{4 + 7 - 1}{7} = \binom{10}{7} = \binom{10}{3} = \frac{10 \times 9 \times 8}{3!} = \frac{720}{6} = 120$$
Answer: There are 120 ways to distribute 7 identical apples among 4 children.
Student Note

Combinations with repetition apply when items are identical (or interchangeable) and categories can hold any number. If the items are distinct and repetition is allowed, that is a different counting problem (treated by the multiplication principle).

Practice 9.4Combinations with Repetition
  1. A bakery sells 4 types of muffins. A customer buys 6 muffins, possibly several of the same type. How many selections are possible?
  2. In how many ways can 10 identical pencils be distributed among 3 students?
  3. A vending machine sells 5 types of snacks. How many different orders of 3 snacks are possible if repetition is allowed and order does not matter?
  4. Explain why \(\binom{5}{3}\) would be the wrong formula for Problem 3 above, and explain what \(\binom{5}{3}\) would count instead.

Stars and Bars as an Introduction

A Geometric Picture of Repetition

The formula \(\binom{n+r-1}{r}\) for combinations with repetition might seem to appear from nowhere. The stars and bars method gives a concrete picture of where it comes from.

Suppose we want to distribute \(r\) identical objects into \(n\) categories. Represent each object as a star (\(\star\)) and use bars (\(\mid\)) to separate the categories. For \(n\) categories, we need exactly \(n-1\) bars to create \(n\) groups.

The total number of symbols is \(r\) stars plus \(n-1\) bars, giving \(r + n - 1\) symbols in total. A valid arrangement corresponds to choosing which \(r\) positions among the \(r+n-1\) total positions are stars (equivalently, which \(n-1\) positions are bars). This gives exactly \(\binom{r+n-1}{r}\) arrangements.

Diagram Instruction

Draw a horizontal row of symbols representing 4 stars and 2 bars in the arrangement ★★ | ★ | ★. Below the row, label the three groups created by the bars as "Coffee," "Tea," and "Juice." Annotate that the count in each group corresponds to the number of stars between (or before/after) consecutive bars: 2 coffee, 1 tea, 1 juice.

A Complete Example

Distribute 4 drinks among 3 categories: coffee (C), tea (T), juice (J). Each arrangement of 4 stars and 2 bars (\(n-1=2\)) represents a valid order.

ArrangementInterpretation
★★★★ | |4 coffee, 0 tea, 0 juice
★★★ | ★ |3 coffee, 1 tea, 0 juice
★★ | ★★ |2 coffee, 2 tea, 0 juice
★★ | ★ | ★2 coffee, 1 tea, 1 juice
★ | ★★★ |1 coffee, 3 tea, 0 juice
| ★★★★ |0 coffee, 4 tea, 0 juice
...and so on

Each of the 15 distinct arrangements of 4 stars and 2 bars corresponds to exactly one drink selection. The number of arrangements is the number of ways to choose which 4 of the 6 positions are stars: \(\binom{6}{4} = 15\), which matches the formula from Section 9.4.

Example 9.5.1
Stars and Bars Setup
  • ProblemUse stars and bars to count the number of ways to place 6 identical marbles into 5 distinct boxes.
  • Think6 marbles are stars; 4 bars (\(n-1=4\)) separate the 5 boxes. The total number of symbols is \(6+4=10\). Choose which 6 of the 10 positions are stars.
  • Solve $$\binom{10}{6} = \binom{10}{4} = \frac{10\times 9\times 8\times 7}{4!} = \frac{5040}{24} = 210$$
Answer: There are 210 ways.
Example 9.5.2
Stars and Bars with Interpretation
  • ProblemA student chooses 3 courses from 4 departments. She may take multiple courses from the same department. How many selections are possible (if we only record the count from each department, not which specific courses)?
  • ThinkChoose 3 items from 4 categories with repetition. Use stars and bars: \(r = 3\), \(n = 4\).
  • Solve $$\binom{4+3-1}{3} = \binom{6}{3} = 20$$
Answer: There are 20 distinct selections.
Practice 9.5Stars and Bars Practice
  1. Use stars and bars to count the ways to distribute 9 identical erasers among 6 students.
  2. For the arrangement ★ | ★★ | | ★★★★ with 4 categories, list the count for each category.
  3. A survey has 5 response categories. A respondent's 8 answers are recorded only by how many fall into each category. How many possible response summaries are there?
  4. Explain in your own words why the number of bars needed is always one less than the number of categories.

Integer Solutions to Equations

Counting Distributions as Solutions

Many distribution problems can be reframed as questions about integer solutions to equations. This reframing connects the stars and bars method to algebra in a useful way.

Non-Negative Integer Solutions

The number of solutions to the equation

$$x_1 + x_2 + \cdots + x_n = r$$

where each \(x_i\) is a non-negative integer (\(x_i \geq 0\)) is:

$$\binom{n+r-1}{r}$$

This is the same as the stars and bars formula: each \(x_i\) counts how many items are placed in category \(i\).

Positive Integer Solutions

If instead each \(x_i \geq 1\) (each category must receive at least one item), substitute \(y_i = x_i - 1\) so that \(y_i \geq 0\) and:

$$y_1 + y_2 + \cdots + y_n = r - n$$

Then the number of solutions is \(\binom{n+(r-n)-1}{r-n} = \binom{r-1}{r-n} = \binom{r-1}{n-1}\), provided \(r \geq n\).

Example 9.6.1
Non-Negative Integer Solutions
  • ProblemFind the number of non-negative integer solutions to \(x_1+x_2+x_3+x_4=12\).
  • ThinkThis is a stars and bars problem with \(n=4\) variables and \(r=12\).
  • Solve $$\binom{4+12-1}{12} = \binom{15}{12} = \binom{15}{3} = \frac{15\times14\times13}{6} = \frac{2730}{6} = 455$$
Answer: There are 455 non-negative integer solutions.
Example 9.6.2
Positive Integer Solutions
  • ProblemFind the number of positive integer solutions to \(x_1+x_2+x_3=9\).
  • ThinkEach variable must be at least 1. Substitute \(y_i = x_i - 1\), so \(y_i \geq 0\) and the equation becomes \(y_1+y_2+y_3=6\). Now apply stars and bars with \(n=3\), \(r=6\).
  • Solve $$\binom{3+6-1}{6} = \binom{8}{6} = \binom{8}{2} = \frac{8\times7}{2} = 28$$
Answer: There are 28 positive integer solutions.
Example 9.6.3
With Lower Bounds Greater Than One
  • ProblemCount the non-negative integer solutions to \(x_1+x_2+x_3=15\) with \(x_1 \geq 2\), \(x_2 \geq 3\), and \(x_3 \geq 0\).
  • ThinkSubstitute to absorb the lower bounds: let \(y_1 = x_1-2\) and \(y_2 = x_2-3\), so \(y_1,y_2 \geq 0\). The equation becomes \((y_1+2)+(y_2+3)+x_3=15\), so \(y_1+y_2+x_3=10\).
  • Solve $$\binom{3+10-1}{10} = \binom{12}{10} = \binom{12}{2} = \frac{12\times11}{2} = 66$$
Answer: There are 66 solutions.
Student Note

The substitution trick is the key step. When a variable has a lower bound other than zero, shift it so the new variable has a zero lower bound, then adjust the right-hand side of the equation accordingly.

Practice 9.6Integer Solution Practice
  1. Find the number of non-negative integer solutions to \(x_1+x_2+x_3+x_4+x_5=10\).
  2. Find the number of positive integer solutions to \(x_1+x_2=7\).
  3. Find the number of non-negative integer solutions to \(x_1+x_2+x_3=14\) with \(x_1\geq 1\) and \(x_2\geq 2\).
  4. A delivery service distributes 11 identical packages among 3 trucks, with each truck required to carry at least 2 packages. In how many ways can this be done?

Partitions as an Introduction

Breaking a Number into Parts

A partition of a positive integer \(n\) is a way of writing \(n\) as an unordered sum of positive integers. The summands are called parts.

For example, the partitions of 4 are: \(4\); \(3+1\); \(2+2\); \(2+1+1\); \(1+1+1+1\). So there are 5 partitions of 4. This count is written \(p(4)=5\).

Partitions differ from the integer-solution problems above in one important way: the order of the parts does not matter. The partition \(2+1+1\) and the partition \(1+2+1\) are the same partition.

Small Partition Counts

\(n\)Partitions\(p(n)\)
111
22; 1+12
33; 2+1; 1+1+13
44; 3+1; 2+2; 2+1+1; 1+1+1+15
5(7 partitions)7
6(11 partitions)11

The partition function \(p(n)\) grows, but without a simple closed-form formula. Partition theory is a deep area of mathematics. At this level, students should be able to list partitions of small integers systematically.

Listing Partitions Systematically

To list all partitions of \(n\): start with the partition \(n\) (only one part equal to \(n\)); decrease the largest part and distribute the remainder into parts no larger than the current largest part; continue until you reach \(1+1+\cdots+1\) (\(n\) ones).

Example 9.7.1
Listing Partitions of 6
  • ProblemList all partitions of 6.
  • ThinkStart with the largest part and work down, ensuring parts are listed in non-increasing order.
  • Solve

    Partitions with largest part 6: 6

    Partitions with largest part 5: 5+1

    Partitions with largest part 4: 4+2; 4+1+1

    Partitions with largest part 3: 3+3; 3+2+1; 3+1+1+1

    Partitions with largest part 2: 2+2+2; 2+2+1+1; 2+1+1+1+1

    Partitions with largest part 1: 1+1+1+1+1+1

Answer: There are p(6) = 11 partitions of 6.
Practice 9.7Partition Practice
  1. List all partitions of 5.
  2. List all partitions of 7 that have largest part equal to 4.
  3. How many partitions of 6 use only odd parts? List them.
  4. Explain why \(3+2+1\) and \(1+2+3\) are considered the same partition, even though they would be different ordered sequences.
MGU Library Connection

Partition theory connects to number theory, generating functions, and combinatorics at a higher level. Students interested in this area may find the MGU Higher Mathematics pathway includes further study of integer partitions and their algebraic properties.

Sections 9.8 – 9.10
Sequences That Define Themselves: Recurrence Relations
Recurrence Relations · Solving Simple Recurrences · Divide-and-Conquer Recurrences

Recurrence Relations

Sequences That Define Themselves

A recurrence relation defines each term of a sequence using earlier terms. Rather than giving a direct formula for the \(n\)-th term, a recurrence describes how each term is built from its predecessors.

The most important requirement for a recurrence is a base case (or several base cases) that provides the starting values from which all subsequent terms are computed.

A Familiar Example: The Fibonacci Sequence

The Fibonacci sequence is defined by:

F(1) = 1, F(2) = 1, F(n) = F(n−1) + F(n−2) for n ≥ 3

The first several terms are: \(1, 1, 2, 3, 5, 8, 13, 21, 34, 55, \ldots\). Each term is the sum of the two before it. This is a recurrence relation.

Why Recurrences Appear in Counting

Many counting problems have recursive structure: the count for size \(n\) naturally depends on the count for smaller sizes. When this happens, writing a recurrence relation captures the structure of the problem.

For example, let \(a_n\) be the number of binary strings of length \(n\) that do not contain two consecutive 1s. Then \(a_1 = 2\) (strings: 0, 1) and \(a_2 = 3\) (strings: 00, 01, 10). For \(n \geq 3\): a string of length \(n\) either starts with 0, followed by any valid string of length \(n-1\), or starts with 10, followed by any valid string of length \(n-2\). So \(a_n = a_{n-1} + a_{n-2}\) — exactly the Fibonacci recurrence.

Example 9.8.1
Setting Up a Recurrence
  • ProblemA staircase has \(n\) steps. A person can climb 1 or 2 steps at a time. Let \(c_n\) be the number of ways to reach the top. Find a recurrence for \(c_n\) and compute the first five terms.
  • ThinkTo reach step \(n\), the person either took a 1-step from step \(n-1\) or a 2-step from step \(n-2\). The number of ways to do this is the number of ways to reach step \(n-1\) plus the number of ways to reach step \(n-2\).
  • Solve

    Base cases: \(c_1 = 1\) (one way: step 1); \(c_2 = 2\) (ways: \(\{1,1\}\) or \(\{2\}\)).

    Recurrence: \(c_n = c_{n-1}+c_{n-2}\) for \(n \geq 3\).

\(n\)\(c_n\)
11
22
33
45
58
Answer: The sequence c_n satisfies the Fibonacci recurrence with shifted base cases.
Practice 9.8Setting Up Recurrences
  1. Let \(d_n\) be the number of binary strings of length \(n\) that do not contain the pattern "11" anywhere. Verify that \(d_n\) satisfies the same recurrence as the staircase problem.
  2. A sequence is defined by \(b_1 = 1\) and \(b_n = b_{n-1} + n\) for \(n \geq 2\). Compute \(b_1\) through \(b_5\).
  3. Explain, in your own words, why a recurrence relation is incomplete without one or more base cases.
  4. For the staircase problem (Example 9.8.1), suppose the person could climb 1, 2, or 3 steps at a time. Write a new recurrence for the number of ways \(c_n\) to reach step \(n\). (You will use this recurrence again in the Skill Practice.)

Solving Simple Recurrences

Unwinding a Recurrence

The simplest technique for solving a recurrence is unwinding (also called iteration or back-substitution): repeatedly apply the recurrence rule, replacing each term with its definition, until a pattern appears.

Example 9.9.1
Solving a Linear Recurrence by Unwinding
  • ProblemLet \(a_1 = 3\) and \(a_n = 2a_{n-1}\) for \(n \geq 2\). Find a closed form for \(a_n\).
  • ThinkThis recurrence doubles each term. Unwind to find the pattern.
  • Solve $$a_n = 2a_{n-1} = 2\cdot 2a_{n-2} = 2^2 a_{n-2} = 2^2\cdot 2a_{n-3} = 2^3 a_{n-3} = \cdots = 2^{n-1}a_1 = 2^{n-1}\cdot 3$$

    So \(a_n = 3 \cdot 2^{n-1}\).

  • CheckFor \(n=1\): \(3\cdot 2^0=3=a_1\). ✓ For \(n=2\): \(3\cdot 2^1=6=2\cdot 3=2a_1\). ✓ For \(n=3\): \(3\cdot 2^2=12=2\cdot 6\). ✓
Answer: a_n = 3 · 2^(n−1)
Example 9.9.2
Arithmetic Recurrence
  • ProblemLet \(a_1=5\) and \(a_n=a_{n-1}+4\) for \(n\geq2\). Find a closed form.
  • ThinkEach step adds 4. After \(n-1\) steps from the base case, we have added 4 a total of \(n-1\) times.
  • Solve $$a_n = a_1 + 4(n-1) = 5+4n-4 = 4n+1$$
  • Check\(a_1=4(1)+1=5\). ✓ \(a_2=4(2)+1=9=5+4\). ✓
Answer: a_n = 4n + 1

The Characteristic Equation Method (Introduction)

For recurrences of the form \(a_n = c_1 a_{n-1} + c_2 a_{n-2}\) (second-order homogeneous linear recurrences), there is a systematic method using characteristic equations.

Assume a solution of the form \(a_n = r^n\). Substituting:

r^n = c₁r^(n−1) + c₂r^(n−2)

Dividing by \(r^{n-2}\):

r² = c₁r + c₂ ⟹ r² − c₁r − c₂ = 0

This is the characteristic equation. Solve for \(r\). If the two roots \(r_1\) and \(r_2\) are distinct, the general solution is:

a_n = A·r₁ⁿ + B·r₂ⁿ

where \(A\) and \(B\) are determined by the base cases.

Example 9.9.3
Characteristic Equation
  • ProblemSolve the recurrence \(a_n=5a_{n-1}-6a_{n-2}\) with \(a_1=2\) and \(a_2=5\).
  • ThinkThis is a second-order linear homogeneous recurrence. Form the characteristic equation.
  • Solve

    Characteristic equation: \(r^2-5r+6=0\). Factor: \((r-2)(r-3)=0\), so \(r_1=2\) and \(r_2=3\).

    General solution: \(a_n = A\cdot 2^n + B\cdot 3^n\).

    Apply initial conditions:

    $$a_1 = 2A+3B = 2 \qquad a_2 = 4A+9B = 5$$

    From the first equation: \(A = \dfrac{2-3B}{2}\). Substitute into the second:

    $$4\cdot\frac{2-3B}{2}+9B=5 \implies 4-6B+9B=5 \implies 3B=1 \implies B=\frac{1}{3}$$

    Then \(A = \dfrac{2-1}{2} = \dfrac{1}{2}\).

    So \(a_n = \dfrac{1}{2}\cdot 2^n + \dfrac{1}{3}\cdot 3^n = 2^{n-1}+3^{n-1}\).

  • Check\(a_1=1+1=2\). ✓ \(a_2=2+3=5\). ✓ \(a_3=5(5)-6(2)=25-12=13\) and \(2^2+3^2=4+9=13\). ✓
Answer: a_n = 2^(n−1) + 3^(n−1)
Practice 9.9Solving Recurrences
  1. Solve \(a_1=4\), \(a_n=2a_{n-1}\) by unwinding to find a closed form.
  2. Solve \(a_1=2\), \(a_n=a_{n-1}+5\) by unwinding to find a closed form.
  3. Use the characteristic equation method to solve \(a_n=4a_{n-1}-3a_{n-2}\) with \(a_1=1\), \(a_2=5\).
  4. Verify your closed form from Problem 3 by computing \(a_3\) two ways: once from the recurrence directly, and once from your closed form.

Divide-and-Conquer Recurrences as an Introduction

Recurrences from Algorithms

Many important algorithms solve a problem of size \(n\) by splitting the input into smaller pieces, solving each piece recursively, and combining the results. The running time of such an algorithm satisfies a divide-and-conquer recurrence.

The Master Theorem (Informal Version)

A common divide-and-conquer recurrence has the form:

T(n) = a·T(n/b) + f(n)

where \(a\) = number of subproblems, \(b\) = factor by which the input size shrinks, and \(f(n)\) = time to split and combine.

This chapter introduces the structure of such recurrences without formal asymptotic analysis. The key insight is that the recurrence captures how much work is done at each level of the recursion.

Example 9.10.1
Binary Search Recurrence
  • ProblemBinary search on a sorted list of \(n\) items works by comparing the target to the middle element, then searching only the left or right half. Let \(T(n)\) be the number of comparisons in the worst case.
  • ThinkThe algorithm makes 1 comparison, then searches a list of size \(n/2\).
  • Solve

    The recurrence is:

    $$T(1) = 1, \qquad T(n) = T\!\left(\frac{n}{2}\right) + 1$$

    Unwind:

    $$T(n) = T(n/2)+1 = T(n/4)+2 = T(n/8)+3 = \cdots$$

    After \(k\) steps: \(T(n)=T(n/2^k)+k\). When \(n/2^k=1\), we have \(k=\log_2 n\).

    So \(T(n) = 1+\log_2 n\).

Answer: Binary search requires at most log₂(n) + 1 comparisons — the work grows very slowly as the input doubles.
Example 9.10.2
Merge Sort Recurrence
  • ProblemMerge sort splits a list of \(n\) elements in half, sorts each half, and merges the results in \(n\) steps. Find a recurrence and describe its growth.
  • ThinkThe recurrence is \(T(n)=2T(n/2)+n\).
  • Solve

    Unwinding:

    $$T(n) = 2T(n/2)+n$$ $$= 2\left(2T(n/4)+\frac{n}{2}\right)+n = 4T(n/4)+n+n = 4T(n/4)+2n$$ $$= 4\left(2T(n/8)+\frac{n}{4}\right)+2n = 8T(n/8)+3n$$

    After \(k\) levels: \(T(n)=2^k T(n/2^k)+kn\). When \(n/2^k=1\), \(k=\log_2 n\).

    $$T(n) = n\cdot T(1) + n\log_2 n = n + n\log_2 n \approx n\log_2 n$$
Answer: Merge sort performs approximately n·log₂(n) operations, which grows much slower than n² (the behavior of simpler sorting methods).
Bridge to Computer Science

Divide-and-conquer recurrences appear throughout algorithm design. The recurrence structure mirrors the recursive structure of the algorithm itself. Chapter 12 of this textbook returns to this connection with a focus on Big-O notation and growth comparisons.

Practice 9.10Divide-and-Conquer Practice
  1. An algorithm splits a problem of size \(n\) into 3 subproblems of size \(n/3\), with \(f(n)=n\) combining work. Write the recurrence \(T(n)\) and unwind it through 2 levels.
  2. Unwind \(T(n)=T(n/2)+2\) with \(T(1)=0\) to find a closed form in terms of \(\log_2 n\).
  3. Explain, in plain language, why \(n\log_2 n\) grows more slowly than \(n^2\) as \(n\) becomes large. (You may compute both for \(n=8\), \(n=16\), and \(n=32\) to support your explanation.)
  4. A recursive algorithm makes 4 recursive calls on subproblems of size \(n/2\), with combining work \(f(n)=n\). Write the recurrence \(T(n)\). Without solving it fully, predict whether its growth will be faster or slower than merge sort's, and explain your reasoning.