Discrete MathematicsRecursion and Recurrences1 of 4
Recursion and Recurrences · 1
Recursively Defined Sequences and Functions
We often know how a sequence steps from one term to the next long before we have a formula that jumps straight to the nth term.
1
Base Cases and Recursive Steps
To describe a sequence like 3,7,11,15,19,… without an explicit formula for spot n, we need a way to fix both where the list starts and how each term builds from the one before it.
Base Cases and Recursive Steps
Using an for the term at spot n and an−1 for the previous term, a recursive definition pairs a starting value with a step rule:
Here, the +4 recursive step sets a spacing of 4 between consecutive terms, while the base case a1=3 fixes where the whole sequence starts on the number line.
Once the step rule is fixed, the spacing between terms stays the same and the starting value alone decides where the whole sequence lands.
2
Writing Recursive Definitions
Next, we want to write a base case and a recursive step when we are given either the first few terms of a sequence or an explicit formula for an.
Writing Recursive Definitions
When each term in 2,6,18,54,162,… (starting at n=1) is 3 times the previous term, the rule multiplies an−1 by 3:
a1an=2,=3an−1for n≥2
When the jump between terms changes at each step, as in 1,2,4,7,11,16,… (starting at n=1), the recursive step uses the spot number n alongside an−1:
a1an=1,=an−1+(n−1)for n≥2
Now let's convert the explicit formula an=2n+5 for n≥0 into a recursive definition.
Text solution
Find the base casePlug the starting index n=0 into the explicit formula.
a0=20+5=1+5=6
Solve the an−1 equation for the part with nWrite the explicit formula at n−1 and isolate 2n−1.
an−1=2n−1+5⟹2n−1=an−1−5
Substitute into anRewrite 2n as 2⋅2n−1 and replace 2n−1 with an−1−5.
So the recursive definition is a0=6 and an=2an−1−5 for n≥1.
3
Evaluating Recursive Functions
Because a sequence is a function whose domain is a set of integers, we can write recursive rules in function notation and evaluate them at a specific input, such as finding f(4) when
f(0)f(n)=1,=n⋅f(n−1)for n≥1
Evaluating Recursive Functions
Text solution
Follow the chain down to the base caseApply the recursive rule from n=4 step by step until it reaches f(0).
f(4)f(3)f(2)f(1)=4⋅f(3),=3⋅f(2),=2⋅f(1),=1⋅f(0)
Substitute values back up the chainStart with the base case f(0)=1 and fill in each product in reverse order.
f(1)f(2)f(3)f(4)=1⋅1=1=2⋅1=2=3⋅2=6=4⋅6=24
So f(4)=24, and in general this recursive rule computes f(n)=n! for all integers n≥0.
4
Well-Defined Recursive Functions
Writing f(n) in terms of another value of f does not automatically define a function; we need to check whether a rule is well-defined on its domain (such as all integers n≥0), meaning it gives every input in the domain a single, clear output.
Well-Defined Recursive Functions
Tracing the chain of steps shows three common ways a recursive rule on n≥0 can fail:
Stepping past the base case: With f(0)=1 and f(n)=f(n−2)+3 for n≥1, odd inputs step back by 2 right past 0:
f(3)→f(1)→f(−1),and −1 is outside the domain
Moving away from the base case: With f(0)=5 and f(n)=f(n+1)−2 for n≥1, the chain moves away from 0 toward +∞:
f(1)→f(2)→f(3)→f(4)→…
Leaving the domain or looping: With f(1)=1 and f(n)=f(2n)+1 for n≥2, the input n=3 asks for f(1.5), which is outside the integer domain; a circular rule like f(n)=f(n)+1 loops forever without reaching a base case.
Across these rules on n≥0, an input has a valid output only when its chain of steps stays on non-negative integers and lands on a base case in finitely many steps.
A recursive rule works only when the IOU chain from every starting number stays in bounds and lands on a base case.
5
Defining Operations Recursively
We also want a precise way to define repeated operations like exponents xn and sums ∑i=1nai without relying on "…" in the middle of an expression.
Defining Operations Recursively
Separating the final operation at step n replaces the three dots with an exact recursive definition. For powers xn (with integer n≥0):
Now we want to find the number of ways an to climb a staircase of n stairs when we can take either 1 stair or 2 stairs at a time.
1-step
2-step
n−2
n−1
n
an−2ways
an−1ways
anways
⋯
Two-Step Recursions and the Fibonacci Sequence
an=?
climb 1 or 2 stairs at a time
1
2
⋯
n−2
n−1
n
Text solution
Split by the final step onto stair nEvery climb to stair n(n≥3) ends either with a 1-stair step from stair n−1(an−1 ways) or a 2-stair step from stair n−2(an−2 ways).
an=an−1+an−2for n≥3
Count the first two base cases directlyBecause the rule looks back two steps, we need both a1(1 way: 1) and a2(2 ways: 1+1 or 2) to start building the sequence.
a1a3a4a5=1,a2=2⟹=2+1=3,=3+2=5,=5+3=8
Starting at index 0 with 0 and 1, the same two-step rule defines the Fibonacci sequence:
f0f1fn=0,=1,=fn−1+fn−2for n≥2
So the staircase count for n stairs is an=fn+1.
7
Strong Induction on Recursive Sequences
We want to prove that the Fibonacci numbers satisfy fn<2n for all integers n≥0. Because fk=fk−1+fk−2 reaches back two steps to both k−1 and k−2, ordinary induction, which only assumes the claim at k−1, isn't enough, so we use strong induction.
Strong Induction on Recursive Sequences
f0=0
f1=1
fn=fn−1+fn−2(n≥2)
Claim: fn<2n for all n≥0
Text solution
Check the two base cases (n=0 and n=1)Verify the inequality at both starting indices before the recursive rule takes over at n=2.
f0f1=0<20=1,=1<21=2
State the strong inductive hypothesisFor an arbitrary integer k≥2, assume fi<2i holds for all integers i with 0≤i≤k−1; since k≥2, both k−1 and k−2 lie in this range.
fk−1<2k−1andfk−2<2k−2
Substitute into the recursive definition for fkReplace fk with fk−1+fk−2, apply both inequalities from the hypothesis, and bound 2k−2 by 2k−1.
Finally, we want to find both a recursive rule and an explicit formula for an, the minimum number of single-disk moves needed to transfer n disks from Peg A to Peg C without ever placing a larger disk on top of a smaller one.
an−1
n−1
A
B
C
1
n−1
A
B
C
an−1
n−1
A
B
C
The Tower of Hanoi and Unrolling Recursions
an=?
(the minimum number of moves)
n disks
A
B
C
Text solution
Set up the recursion from the three transfer phasesThe first time the largest disk leaves Peg A, the top n−1 disks must all be stacked on the third peg (at least an−1 moves); the largest disk moves at least once; and after its last move onto Peg C, the n−1 disks still have to move onto it (at least an−1 moves). Moving the n−1 disks to Peg B, the bottom disk to Peg C, and the n−1 disks onto Peg C uses exactly this many moves.
a1an=1,=2an−1+1for n≥2
Unroll the recursion down to a1Substitute the recursive rule into itself n−1 times to reach a1=1, then evaluate the resulting sum of powers of 2.
Prove an=2n−1 for n≥1 by inductionCheck n=1(a1=1=21−1), assume ak=2k−1 for an arbitrary integer k≥1, and substitute into the recursive rule for ak+1.
So transferring n disks takes a minimum of 2n−1 moves for all integers n≥1.
Because moving k disks takes two (k−1)-disk transfers plus 1 move of the largest disk, the number of transfers doubles at each level, and each transfer makes exactly one move of its own largest disk, so the moves add up to 1+2+4+⋯+2n−1=2n−1.
Unrolling a Tower of Hanoi transfer level by level doubles the smaller transfers at each step and leaves one middle move per split, building a sum of powers of two.
Key concepts
A recursive definition builds a sequence or operation from the bottom up by pairing base cases with a recursive step. The number of base cases must match how far back the step looks: a one-step rule like a1=3,an=an−1+4 needs one starting value, while a two-step rule like the Fibonacci sequence f0=0,f1=1,fn=fn−1+fn−2 needs two. To check whether a function rule is well-defined on a domain like n≥0, trace the chain of steps from any starting integer n and verify that it stays inside the domain and hits a base case in finitely many steps. For example, if f(n)=f(n−2)+3 only gives f(0)=1, then f(3)→f(1)→f(−1) steps right past 0 and fails.
To convert between explicit and recursive forms, work in the direction the problem asks:
Explicit to recursive
Write an and an−1 next to each other, solve the an−1 formula for the n-dependent term (such as 2n−1=an−1−5 from an=2n+5), and substitute it into an.
Recursive to explicit
Unroll the recurrence backward step by step (an=2an−1+1=22an−2+2+1=…) until it reaches the base case, or compute the first few terms to spot the pattern, and then prove the explicit formula by induction.
In any induction proof on a recursive sequence, the inductive step has two parts: rewrite the new term using the recursive definition, then substitute the inductive hypothesis. When the recursive rule only looks back one step (like ak+1=2ak+1), ordinary induction with one base case already gives you ak, so you don't need strong induction. Switch to strong induction, checking all matching base cases first, whenever the recursive step reaches back two or more steps (like fk=fk−1+fk−2).
9
Practice
1
Write a recursive definition (base case and recursive step) for the sequence a1,a2,a3,… that begins 4,6,10,16,24,34,….
Write the jump an−an−1 between each pair of consecutive terms and compare each jump to the index n.
The jumps between consecutive terms are a2−a1=2,a3−a2=4,a4−a3=6,a5−a4=8, and a6−a5=10. To reach spot n, we add 2(n−1) to the previous term an−1. (Watch out for the common mistake of matching the first jump +2 to n=1 and writing an=an−1+2n, which gives a2=4+2(2)=8 instead of 6.)
Base case: a1Recursive step: an=4=an−1+2(n−1)for all integers n≥2
2
Convert the explicit formula an=3n−4 (for integers n≥0) into a recursive definition.
Write the equations for an and an−1 next to each other, and solve the an−1 equation for 3n−1.
For the base case, plug in n=0:
a0=30−4=1−4=−3
For n≥1, write an=3n−4 and an−1=3n−1−4. Solving the second equation for 3n−1 gives 3n−1=an−1+4. Substituting this into an=3(3n−1)−4 gives:
an=3(an−1+4)−4=3an−1+12−4=3an−1+8
(Be careful not to triple only the 3n−1 piece and write an=3an−1−4, which gives a1=3(−3)−4=−13 instead of 31−4=−1.)
Base case: a0Recursive step: an=−3=3an−1+8for all integers n≥1
3
Each rule below attempts to define a function f on the domain of all integers n≥0. Determine which rule is well-defined, compute f(4) for the well-defined rule, and explain why the other two fail by tracing their chains of steps. (a) f(0)=2,f(1)=3, and f(n)=2f(n−2)−1 for n≥2. (b) f(0)=1,f(1)=2, and f(n)=f(n−3)+4 for n≥2. (c) f(0)=4, and f(n)=f(n−1)+f(n) for n≥1.
For each rule, check how many steps the recursive formula looks back and trace the chain of steps starting from the first integer n where the recursive step applies.
Only (a) is well-defined.
In (a), the recursive step looks back 2 steps for n≥2 and both f(0) and f(1) are given as base cases, so every even n≥0 reaches f(0) and every odd n≥1 reaches f(1) in finitely many steps. Evaluating on the even chain from f(0)=2:
f(2)f(4)=2f(0)−1=2(2)−1=3,=2f(2)−1=2(3)−1=5
(Do not plug f(1)=3 into the step for f(2) as if the rule were 2f(n−1)−1; that gives f(2)=5,f(3)=9, and f(4)=17.)
In (b), the rule steps back by 3 starting at n=2, but only two base cases are given. Asking for f(2) produces the chain
f(2)→f(−1)
which steps right past f(0) and f(1) to −1, outside the domain, where no rule defines f.
In (c), asking for f(1) requires f(1) on the right-hand side (f(1)=f(0)+f(1)), creating an immediate circular loop f(1)→f(1)→… that never ends.
So only (a) is well-defined, and f(4)=5.
4
Give a recursive definition of the product notation ∏i=1nai=a1⋅a2⋅⋯⋅an for all integers n≥1.
Group the product of the first n−1 factors together and separate the final factor at i=n.
Separate the nth factor an from the product of the first n−1 factors. (Make sure to multiply by an rather than adding an as in a sum, and start the recursive step at n≥2 so n=1 does not ask for ∏i=10ai outside the domain n≥1.)
Base case: i=1∏1aiRecursive step: i=1∏nai=a1=(i=1∏n−1ai)⋅anfor all integers n≥2
5
You are climbing a staircase of n stairs (n≥1) and can take 1,2, or 3 stairs in a single step. Let an be the number of different ways to climb to the top of n stairs. Write a complete recursive definition for an (including all necessary base cases) and use it to compute a5.
Be careful not to miss the single 3-stair step and write a3=3, which would give a4=6 and a5=11.
Look at the final step onto stair n and ask which stairs it could have come from, then check how many starting stairs you must count by hand before that rule applies.
For any n≥4, look at the final step onto stair n: you either stepped up 1 stair from stair n−1(an−1 ways), 2 stairs from stair n−2(an−2 ways), or 3 stairs from stair n−3(an−3 ways). Because these three possibilities for the final step have no overlap and cover every valid climb,
an=an−1+an−2+an−3for all integers n≥4
Because the recursive step looks back three steps, we need three base cases (giving only a1 and a2 would make a3 ask for an undefined term a0):
a1=1(1)
a2=2(1+1, or 2)
a3=4(1+1+1,1+2,2+1, or 3). Be careful not to miss the single 3-stair step and write a3=3, which would give a4=6 and a5=11.
Using the recurrence to reach a5:
a4a5=a3+a2+a1=4+2+1=7=a4+a3+a2=7+4+2=13
6
A sequence is defined recursively by a0=5 and an=2an−1−3 for all integers n≥1. Unroll the recursion to find an explicit formula for an, and then prove your formula by mathematical induction.
Make sure to multiply the −3 inside the parentheses by 2 at each step; forgetting to distribute the 2 gives 5⋅2n−3n instead of a geometric sum.
At each unrolling step, keep the powers of 2 factored out of −3 so you can see the geometric sum 1+2+22+… forming.
(Make sure to multiply the −3 inside the parentheses by 2 at each step; forgetting to distribute the 2 gives 5⋅2n−3n instead of a geometric sum.) Continuing all n steps back to a0 gives:
Proof by mathematical inductionthat an=2n+1+3 for all integers n≥0:
Base case (n=0)By definition, a0=5, and the formula gives 20+1+3=2+3=5.
Inductive stepLet k≥0 be an arbitrary integer and assume that ak=2k+1+3. We must show that ak+1=2(k+1)+1+3=2k+2+3. By the recursive definition and the inductive hypothesis,
ak+1=2ak−3=2(2k+1+3)−3=2k+2+6−3=2k+2+3
By mathematical induction, an=2n+1+3 for all integers n≥0.
7
A sequence is defined recursively by a0=2,a1=5, and an=5an−1−6an−2 for all integers n≥2. Prove by strong induction that an=2n+3n for all integers n≥0.
Check both n=0 and n=1 in the base step; in the inductive step for k≥2, substitute for both ak−1 and ak−2, then factor 2k−2 out of the powers of 2 and 3k−2 out of the powers of 3.
Proof by strong induction:
Base casesBecause the recursive step applies for n≥2, we check both n=0 and n=1. (Checking only n=0 and starting the inductive step at k=1 would make the recurrence ask for a−1, which is outside the domain n≥0.)
For n=0:a0=2, and 20+30=1+1=2.
For n=1:a1=5, and 21+31=2+3=5.
Inductive stepLet k≥2 be an arbitrary integer, and assume by strong induction that ai=2i+3i holds for all integers i with 0≤i≤k−1. Because k≥2, both k−1 and k−2 lie in this range, so ak−1=2k−1+3k−1 and ak−2=2k−2+3k−2. By the recursive definition and the strong inductive hypothesis,
ak=5ak−1−6ak−2=5(2k−1+3k−1)−6(2k−2+3k−2)
(Do not multiply the bases to turn 5⋅2k−1 into 10k−1 or add bases to turn 2k−1+3k−1 into 5k−1; instead, group the powers of 2 and the powers of 3 separately and factor out 2k−2 and 3k−2.)