University Discrete Math · Sheet 08 of 9 All 9 sheets →
  1. Home
  2. Worksheets
  3. University Discrete Math
  4. Recurrence Relations and Advanced Counting
University Discrete Math Recurrence Relations and Advanced Counting Free · no sign-up

University Discrete Mathematics — Recurrence Relations and Advanced Counting Worksheet

Two halves that meet in the middle. First, counting problems that are easier to describe than to count directly: define a sequence, condition on the last choice, and justify a recurrence that ties the case you want to smaller cases of itself. Then the machinery that turns such a recurrence into a formula — the characteristic equation, distinct roots, and the repeated root that needs an extra factor of n. Alongside them, the counting principle that repairs overcounting: inclusion-exclusion for two and three sets, upper bounds on how much of something anyone may take, and the two standard applications, derangements and onto functions. Have a look on this page, then print the free PDF when you want to write on it.

Page 1 of the University Discrete Math Recurrence Relations and Advanced Counting practice worksheet

Practice worksheet — free PDF

5 pages 9 questions Letter size, print-ready

No email, no account, no watermark. Teachers: photocopy it for your classes freely. Worked solutions and 6 harder problems come with the University Discrete Math bundle.

All 9 questions

Each question targets one named concept from the sheet. Read them here, or print the PDF — it has working space under each one.

  1. Q1Modelling a Counting Problem with a Recurrence

    A door code is a string of n digits taken from 1,2,,9 (no zero), and a code is valid if no two consecutive digits are both even. Let cn be the number of valid codes of length n.

    1. Find c1 and c2.
    2. By considering the last digit of a valid code, show that cn=5cn1+20cn2 for n3.
    3. Compute c4.
  2. Q2Modelling a Counting Problem with a Recurrence

    A librarian places n different books on three different shelves. On each shelf the books stand in a row from left to right, and a shelf may be left empty. Two placements are the same only when every shelf holds the same books in the same order. Let sn be the number of placements.

    1. Find s1 and s2.
    2. Place the books in the order 1,2,,n. By counting the positions available to the last book once the first n1 are on the shelves, find a recurrence expressing sn in terms of sn1 for n2, and justify it.
    3. Compute s5, and write sn in terms of factorials.
  3. Q3Linear Homogeneous Recurrences with Distinct Roots

    Solve the recurrence an=an1+6an2 for n2, with a0=3 and a1=4. Check your formula against a2 computed from the recurrence.

  4. Q4Linear Homogeneous Recurrences with Distinct Roots

    A sequence satisfies an+1=2an+8an1 for n2, with a1=4 and a2=4. Find a closed form for an, n1, and check it against a3.

  5. Q5Linear Homogeneous Recurrences with a Repeated Root

    Solve an=6an19an2 for n2, with a0=2 and a1=3, and check your formula against a2 and a3 computed from the recurrence.

  6. Q6The Inclusion-Exclusion Principle

    How many integers from 1 to 1000 inclusive are divisible by none of 4, 6 and 15?

  7. Q7The Inclusion-Exclusion Principle

    A food bank has 14 identical one-hour shifts to hand out among 4 volunteers, and no volunteer may take more than 5 shifts (a volunteer may take none). In how many ways can the shifts be handed out? You may use the fact that the equation x1+x2++xk=m has (m+k1k1) solutions in nonnegative integers.

  8. Q8Counting Derangements and Onto Functions
    1. Five distinct manuscripts are sent to three editors, every manuscript going to exactly one editor, and every editor must receive at least one. In other words, count the surjective (onto) functions from a 5-element set to a 3-element set: the functions that hit every element of the target.
    2. Five reviewers each wrote a report, and the reports are collected and handed back so that each reviewer checks one report — never their own. In how many ways can this be done?
  9. Q9Synthesis — drawing on several topics in this unit

    A signal occupies n consecutive time slots and is built as a sequence of pulses: a short pulse fills one slot and can be sent at any of 2 frequencies; a long pulse fills two slots and can be sent at any of 3 frequencies. Let an be the number of different signals filling exactly n slots, with a0=1 (the empty signal).

    1. Explain why an=2an1+3an2 for n2, and give a1.
    2. Solve the recurrence, and check your formula against a4.

The 6 challenge problems for this topic are a separate, paid sheet and are not reproduced here.

What does this set assume? This set assumes Secondary 5 mathematics only — algebraic manipulation, factoring a quadratic and the exponent laws are all the algebra it uses, and there is no calculus and no linear algebra anywhere in it, whatever a calendar lists as a prerequisite. From this course it leans on two earlier sets. Counting Techniques supplies the addition and multiplication principles, permutations and combinations, and combinations with repetition, all of which the counting questions here use without re-deriving. Induction and Recursion supplies the idea of a recursively defined sequence and the habit of justifying a step rather than asserting it; that set defines such sequences, and this one models and solves them. The scope stops at linear homogeneous recurrences of degree two with constant coefficients, in the two cases the characteristic equation can produce: distinct roots and a repeated root. Nonhomogeneous recurrences, divide-and-conquer recurrences and generating functions are all out of this course. So is probability: a question here may ask how many arrangements there are, never how likely one is.

Which course is this for? In the public course calendars of Montreal universities, this material is part of the courses numbered MATH 240, MAT1500, INF1132 and MAT210. Each course orders and weights the topics its own way, so check your own outline for what your exam covers. Which sets match your course.

How to do every concept on this sheet

This is the part worksheet sites usually leave out. Below is the actual reasoning behind each group of questions — not a full solution set, the decisions that get you to one. Read it before you start, or after you get stuck.

Modelling a counting problem with a recurrence

A recurrence is an argument, not a formula you spot. The argument always has the same shape: take an arbitrary object of size n, look at one feature of it — usually the last choice made — split into cases according to that feature, and show that each case is counted by a smaller member of the same sequence. Q1 and Q2 both name the feature to condition on, so the work is in the justification, not in the guessing.

Building a recurrence

Four moves, in this order.

  1. 1
    Say what the sequence counts

    One sentence: aₙ is the number of objects of size n satisfying the stated condition. Every later claim is checked against this sentence.

  2. 2
    Get the small values by listing

    Do not derive them. Write out the objects of size 1, and of size 2 if that is quick, and count what you wrote.

  3. 3
    Condition on the last choice

    Split the objects of size n into cases by that last choice. The cases must be disjoint and must together cover everything — say so, in words.

  4. 4
    Match each case to a smaller term

    Show that removing the last choice from a case leaves exactly one object counted by aₙ₋₁ or aₙ₋₂, and that every such smaller object arises exactly once.

Q1 is the version where the last choice constrains the one before it. The condition forbids a pattern in two consecutive positions, so knowing the last digit alone is not enough to know how many valid codes end that way — you have to know whether the last digit is of the kind that restricts its neighbour. That is exactly why a term two steps back appears in the recurrence the question asks you to establish, and why the sequence needs two starting values. Part (a) asks for those two by direct count; part (c) then asks you to run the recurrence forward, which is also your check that parts (a) and (b) agree with each other.

Say why the cases do not overlap. "Show that" in Q1(b) is a request for a proof, and the marks are in the sentence stating that every valid code of length n falls into exactly one of the cases and that the correspondence with shorter codes is one-to-one. A line of arithmetic that lands on the right coefficients is not the same argument.

Q2 is the version with a one-term recurrence, and it is worth seeing why. The question fixes an order on the items being placed and asks you to count the positions available to the last one once the others are already on the shelves. Because the shelves are distinguishable and each shelf holds its items in a left-to-right row, a new item can go at either end of a shelf or in any gap between two items already on it — so the number of positions available depends only on how many items are already placed, not on how they happen to be spread out. That independence is the whole content of the justification part (b) asks for. Part (c) then asks for sₙ in terms of factorials: unfold the recurrence, write the product of the successive multipliers, and recognise that product as a ratio of factorials.

Check a modelled recurrence on a value you counted by hand. Both questions give you small terms in part (a) and a larger term to compute in part (c). Running the recurrence up from the small terms and comparing against a direct count of a middle case costs a minute and catches a coefficient that is off by one, which no amount of re-reading the argument will.

Linear homogeneous recurrences with distinct roots

A recurrence of the form aₙ = p·aₙ₋₁ + q·aₙ₋₂ is linear (each earlier term appears to the first power), homogeneous (no term free of the sequence) and has constant coefficients. For these, and only for these, there is a method. Try a solution of the form aₙ = rⁿ, substitute, and divide by the lowest power of r that appears: what is left is a quadratic in r.

aₙ = p·aₙ₋₁ + q·aₙ₋₂ ⇒ r² = p·r + q ⇒ r² − p·r − q = 0

Solving one, start to finish

The same five steps for Q3 and Q4.

  1. 1
    Write it in standard form

    All the sequence terms on the left, highest index first, coefficients read off directly.

  2. 2
    Write and solve the characteristic equation

    Factor it if it factors; otherwise the quadratic formula. Two different roots put you in this case.

  3. 3
    Write the general solution

    aₙ = c₁·r₁ⁿ + c₂·r₂ⁿ, with two constants still unknown.

  4. 4
    Impose the two given values

    Substitute the two indices you were given. That is a two-by-two linear system in c₁ and c₂; solve it.

  5. 5
    Check

    Compute one further term from the recurrence and the same term from your formula, and see that they agree.

Q3 is the method in its plainest form: the two initial values sit at the first two indices, the characteristic equation factors over the integers, and the question names the term you should check against. Do that check — it is the only step that catches a sign error in a root or an arithmetic slip in the system.

Q4 changes two things at once, deliberately. The recurrence is written with its highest term as aₙ₊₁ rather than aₙ, and the two given values sit at indices 1 and 2 rather than 0 and 1. The shift is cosmetic — rewrite the relation with the index lowered by one so that it matches the standard form before you read off the coefficients — but the initial values are not. Substitute n = 1 and n = 2 into the general solution, not n = 0 and n = 1, or the constants will solve a system that belongs to a different sequence. The closed form is wanted for n ≥ 1, and the check is against a term you compute from the recurrence itself.

A shifted index is the most common lost mark on this sheet. Before doing any algebra, write the recurrence twice: once as given, once with every index reduced so the highest is aₙ. Confirm the two say the same thing, then work only from the second.

The repeated root, and why n appears

When the characteristic equation has a discriminant of zero it has one root r, used twice, and c₁·rⁿ + c₂·rⁿ collapses into a single constant times rⁿ — one constant is not enough to meet two initial conditions. The second independent solution is n·rⁿ, so the general solution carries a factor of n on one term.

one repeated root r ⇒ aₙ = (c₁ + c₂·n)·rⁿ

Q5 is that case. Recognise it before you start writing constants: a perfect-square quadratic is the signal, and factoring it is faster than the discriminant. Then substitute the two given indices, solve for c₁ and c₂, and check against both of the terms the question names — two checks, because a repeated-root formula that is wrong in the n-term can still agree at one index by accident.

Where the extra factor comes from. You are not asked to prove it here, but it is worth knowing that (c₁ + c₂·n)·rⁿ satisfying the recurrence is a direct substitution: put it in, collect the terms without n and the terms with n separately, and each group vanishes precisely because r is a double root. Trying the substitution once, outside the question, is what makes the formula stop looking arbitrary.

The inclusion-exclusion principle

Adding the sizes of overlapping sets counts each shared element more than once. The inclusion-exclusion principle is the bookkeeping that repairs it: add the sets, subtract every pairwise overlap, add back every triple overlap, and so on with alternating signs.

|X ∪ Y ∪ Z| = |X| + |Y| + |Z| − |X ∩ Y| − |X ∩ Z| − |Y ∩ Z| + |X ∩ Y ∩ Z|

Q6 asks for a count of the integers in a range divisible by none of three given numbers, which is the complement of a union. So there are two decisions before any arithmetic: name the three sets precisely, and decide to count the union and subtract from the size of the whole range rather than trying to describe "none of them" directly.

An intersection of divisibility conditions is governed by the lcm, not the product. The integers divisible by both d and e are exactly the multiples of lcm(d, e), and that equals d·e only when d and e share no factor. Two of the three numbers in Q6 are not coprime, so multiplying them gives a set that is too small and every later term inherits the error. The count of multiples of d from 1 to N is ⌊N/d⌋ — use the floor throughout, and never round.

Q7 is inclusion-exclusion used the other way round: not on three sets you are given, but on conditions you construct. The question supplies the formula for the number of nonnegative integer solutions of x₁ + x₂ + … + xₖ = m, which counts the distributions with no upper limit at all. The cap each volunteer faces is then handled by subtracting the distributions that violate it.

Handling an upper bound

The substitution that makes the correction terms countable.

  1. 1
    Count with no cap

    Apply the formula the question gives, with m the total to hand out and k the number of people.

  2. 2
    Define the bad sets

    Let Aᵢ be the distributions in which person i exceeds the cap — that is, takes at least one more than the cap allows.

  3. 3
    Count one bad set by substitution

    If person i must take at least b, write xᵢ = yᵢ + b with yᵢ ≥ 0. The equation becomes the same kind of equation with a smaller total, and the same formula counts it.

  4. 4
    Alternate the signs

    Subtract the single sets, add back the pairs, and stop as soon as a term forces a negative total — such a term counts nothing.

By symmetry every Aᵢ has the same size and every pairwise intersection has the same size, so the work is one count per level multiplied by C(k, 1), C(k, 2) and so on. Say that the sets are symmetric rather than leaving the multiplier unexplained.

Derangements and onto functions

Q8 is the pair of classical applications, one in each part, and both are inclusion-exclusion over the things that are missed or fixed.

Part (a) counts the onto (surjective) functions from a set of n elements to a set of m elements. The functions that are not onto are those missing at least one target value, and the ones missing a chosen set of k targets are just the functions into the remaining m − k values — of which there are (m − k)ⁿ. Inclusion-exclusion over which targets are missed gives the standard alternating sum.

onto functions = Σ over k = 0 to m of (−1)ᵏ · C(m, k) · (m − k)ⁿ

Part (b) counts derangements — the arrangements in which nothing stays where it started. Here the bad sets are the arrangements that fix a chosen element, and fixing a chosen set of k elements leaves the other n − k free, so that set has (n − k)! members. The same alternating sum, divided through by n!, gives the familiar series form.

Dₙ = n! · (1 − 1/1! + 1/2! − 1/3! + … + (−1)ⁿ/n!)

Two ways to reach a derangement count, and one to check it. The series above is one. The recurrence Dₙ = (n − 1)·(Dₙ₋₁ + Dₙ₋₂) is the other, and it is a modelling argument of exactly the kind Q1 and Q2 ask for. Computing part (b) both ways is a free check, and it is also the point at which the two halves of this set visibly meet.

Deranging is not the same as "not all fixed". A derangement requires every element to move. Counting the arrangements that leave at least one element in place and subtracting is correct; subtracting only the arrangement that leaves everything in place is not.

The synthesis question

Q9 puts the two halves in one problem. Part (a) is the modelling of Q1: a sequence counting signals built from pieces of two different lengths, where conditioning on the last piece splits into a case that consumes one slot and a case that consumes two, each weighted by the number of frequencies that piece can carry. Justify the split and say why the cases are disjoint, then find the missing starting value by listing the signals that fill a single slot — the empty signal is given for you, and it is given precisely so that the recurrence works from n = 2 without a separate argument.

Part (b) is Q3 and Q4: standard form, characteristic equation, general solution, the two starting values, and then the check the question names against a term computed directly from the recurrence. If the check fails, it is almost always part (a) that is wrong rather than the algebra — re-run the recurrence by hand from the starting values and compare with a direct count of the short signals.

Preview all 5 pages

Click any page to open the full PDF.

Page 1 of the University Discrete Math Recurrence Relations and Advanced Counting practice worksheet
Page 1
Page 2 of the University Discrete Math Recurrence Relations and Advanced Counting practice worksheet
Page 2
Page 3 of the University Discrete Math Recurrence Relations and Advanced Counting practice worksheet
Page 3
Page 4 of the University Discrete Math Recurrence Relations and Advanced Counting practice worksheet
Page 4
Page 5 of the University Discrete Math Recurrence Relations and Advanced Counting practice worksheet
Page 5

Getting the most out of it

Count small cases before you model anything

Write out the objects of size 1 and 2 in full and count them, even when the question does not ask. Those numbers are both your initial conditions and the test data for every claim you make afterwards. A recurrence that disagrees with a hand count at n = 3 is wrong, and finding that out early costs nothing.

Write the case split in words before the equation

"Every valid object of size n either ends in this or ends in that, and never both" is the sentence the marks are for. The equation follows from it in one line. Written the other way round — equation first, justification bolted on — the justification tends to describe the equation rather than prove it.

Normalise the indices, every time

Before solving, rewrite the recurrence so the highest term is aₙ and the initial conditions are written as substitutions into the general solution rather than as terms of the sequence. Most wrong closed forms on this topic are right formulas with constants fitted at the wrong indices.

Name every set, in full, before writing an inclusion-exclusion line

Write "A is the set of … in the range" for each set, then the union formula, then the substitutions. When the sets are defined by divisibility, note the lcm of each pair on the same line so that the intersection sizes cannot be taken from products by reflex.

Verify the closed form against the recurrence

A closed form is a claim about every term, so testing it at one new index is cheap and surprisingly effective. Compute a term from the recurrence, compute it from the formula, and write both down. Several of these questions ask for exactly that check; do it on the ones that do not, too.

Want the solutions, or something more challenging?

The worksheet, the questions above and every explanation on this page stay free permanently. Three more PDFs exist for this topic — the worked answer key, a harder problem set, and the answer key to that. They come with the University Discrete Math Solutions Bundle, beside the unit notes and the unit test, which is what keeps the rest of the series free.

What else exists for Recurrence Relations and Advanced Counting

Three PDFs · 12 pages · all three are in the bundle below.

  • Answer key — 3 pages. All 9 questions worked step by step, including the restrictions and the justifications. Not a list of final answers.
  • Challenge problems — 6 pages, 6 problems. A separate sheet at exam-plus difficulty covering the same 5 concepts. Harder than anything on the free sheet.
  • Challenge answer key — 3 pages. Every challenge problem worked to the same standard, with the checks shown.
  • PDF, letter size, print-ready.
In the bundle See what's in it Not sold separately

The one thing that's for sale

Best value for the whole year

Every University Discrete Math topic — the complete Solutions Bundle

One download, one payment, the whole program. For all 9 University Discrete Math units: the worksheet, the reference notes, the challenge set, the unit test and every answer key — including this one.

9 units · 36 PDFs · 155 pages$24.99
  • Worked solutions, not answer lists — every step written out
  • Covers the whole year's program at this level
  • Less than the price of one hour of tutoring — for the entire year's solutions
Everything paid, in one file $24.99CAD · one payment University Discrete Math bundle — coming soon Not on sale yet

Taking Secondary 1 Math as well? The Secondary 1 Math bundle covers all 15 of its units — 106 PDFs, 474 pages — on the same terms.

Taking Secondary 2 Math as well? The Secondary 2 Math bundle covers all 14 of its units — 98 PDFs, 449 pages — on the same terms.

Taking Secondary 3 Math as well? The Secondary 3 Math bundle covers all 11 of its units — 77 PDFs, 367 pages — on the same terms.

Taking Secondary 4 Math as well? The Secondary 4 Math bundle covers all 17 of its units — 122 PDFs, 466 pages — on the same terms.

Taking Secondary 5 Math as well? The Secondary 5 Math bundle covers all 21 of its units — 147 PDFs, 589 pages — on the same terms.

Taking CEGEP Calculus I as well? The CEGEP Calculus I bundle covers all 9 of its units — 72 PDFs, 371 pages — on the same terms.

Taking CEGEP Calculus II as well? The CEGEP Calculus II bundle covers all 8 of its units — 64 PDFs, 335 pages — on the same terms.

Taking CEGEP Linear Algebra as well? The CEGEP Linear Algebra bundle covers all 7 of its units — 56 PDFs, 298 pages — on the same terms.

Taking University Calculus III as well? The University Calculus III bundle covers all 9 of its units — 72 PDFs, 516 pages — on the same terms.

Taking University Linear Algebra as well? The University Linear Algebra bundle covers all 9 of its units — 72 PDFs, 496 pages — on the same terms.

Taking University Differential Equations as well? The University Differential Equations bundle covers all 9 of its units — 36 PDFs, 182 pages — on the same terms.

Taking University Business Math as well? The University Business Math bundle covers all 9 of its units — 36 PDFs, 190 pages — on the same terms.

Taking University Introductory Statistics as well? The University Introductory Statistics bundle covers all 9 of its units — 36 PDFs, 186 pages — on the same terms.

Taking AP Calculus AB as well? The AP Calculus AB bundle covers all 8 of its units — 64 PDFs, 527 pages — on the same terms.

Common questions

Is this worksheet really free?

Yes — the questions are on this page to read, and the PDF downloads directly, no email and no account. The one paid item is optional: the complete University Discrete Mathematics Solutions Bundle, which covers every set at this level.

Which university courses is this for?

The course codes listed on this page are taken from the public course calendars of universities that teach discrete mathematics to mathematics, computer science and engineering students. Each course orders and weights the chapters its own way, and some reach a chapter late in the term or not at all — so check the outline for your own section to see where this set falls in your term.

What do I need to know before starting this set?

Secondary 5 algebra — factoring a quadratic, the quadratic formula and the exponent laws — plus two earlier sets in this course: Counting Techniques, for permutations, combinations and the basic counting principles, and Induction and Recursion, for what a recursively defined sequence is. No calculus and no linear algebra are used anywhere in the set.

Why does a repeated root need an extra factor of n?

Because with one root the two pieces c₁·rⁿ and c₂·rⁿ combine into a single constant times rⁿ, and one constant cannot satisfy two initial conditions. A second, genuinely different solution is needed, and n·rⁿ is one — substituting it into the recurrence works out exactly when r is a double root.

How do I know whether my recurrence is right?

Run it. Use the initial values you counted by hand to generate the next two or three terms, then count those cases directly and compare. A recurrence is a claim about every size, so one disagreement at a small size settles it, and agreement at two or three sizes is strong evidence that the case split is complete.

When do I need inclusion-exclusion instead of just subtracting?

Whenever the things you want to remove overlap. If the conditions you are excluding can hold at the same time, subtracting each count separately removes the overlaps twice, and the alternating terms are what put them back. If the excluded cases are genuinely disjoint, plain subtraction is already correct.

Are generating functions on this worksheet?

No. This course stops at linear homogeneous recurrences of degree two with constant coefficients, solved through the characteristic equation. Generating functions, nonhomogeneous recurrences and divide-and-conquer recurrences are all outside its scope.

Is there any probability in these counting questions?

No. This course counts and stops there — how many arrangements, never how likely one is. Probability, including the counting that feeds it, belongs to University Introductory Statistics.

Can teachers use this in class?

Yes. Print and photocopy it for your own classes freely — I just ask that the tutorinmontreal.ca footer stays on the page.

I'm stuck on one question. Can you help?

Yes — through one-on-one tutoring, in Montreal or online. Get in touch to arrange a session, or see the current rates.

← All 9 University Discrete Math worksheets  ·  Secondary 1 Math series (15 sheets) →  ·  Secondary 2 Math series (14 sheets) →  ·  Secondary 3 Math series (11 sheets) →  ·  Secondary 4 Math series (17 sheets) →  ·  Secondary 5 Math series (21 sheets) →  ·  CEGEP Calculus I series (9 sheets) →  ·  CEGEP Calculus II series (8 sheets) →  ·  CEGEP Linear Algebra series (7 sheets) →  ·  University Calculus III series (9 sheets) →  ·  University Linear Algebra series (9 sheets) →  ·  University Differential Equations series (9 sheets) →  ·  University Business Math series (9 sheets) →  ·  University Introductory Statistics series (9 sheets) →  ·  AP Calculus AB series (8 sheets) →

Download the free worksheet

Ready to improve your grades?

WhatsApp is the way to reach me — tell me the course you're taking and what you're stuck on, and we'll sort out a first session from there.

Message Me on WhatsApp

or send a message

I reply within a day, usually sooner. Your details are used only to answer you — see the Privacy Policy.

Private math & science tutoring in Montreal, QC — Westmount · Outremont · Town of Mount Royal · Hampstead · Côte-Saint-Luc · NDG · Nuns' Island · West Island — and online across Quebec.

Chat with Marius