Discrete MathematicsRecursion and Recurrences2 of 4
Recursion and Recurrences · 2
Recursively Defined Sets and Structural Induction
When a collection of objects branches or nests instead of lining up in a single list a1,a2,a3,…, we can't define it with a sequence formula. Instead, we define the entire set recursively by giving the starting objects and the rules for building new ones.
The Factory: Recursively Defined Sets
Every recursively defined set S works like a factory with three rules:
1. Starter Pack (base case):3∈S2. Builder Machine (recursive step):If x,y∈S, then x+y∈S3. Locked Door (exclusion):Nothing else is in S unless builtfrom the starters by the machines.
For multiples of 3, writing 3n is simpler. A recursive definition is really useful when the objects aren't numbers in a line, such as strings of balanced parentheses or branching binary trees.
Building Parentheses and Binary Trees
Balanced parentheses P:Starter: ()∈PMachines: If x,y∈P, thenWrapper(x)∈P and Gluerxy∈PFull binary trees:Starter: ∙Machine: Connect a new top dotdown to existing trees T1 and T2
Every string built by wrapping or gluing existing strings stays balanced and properly nested, while some strings like ()()() can be built in more than one way and broken strings like ())(() can never be formed.
Every string built by wrapping or gluing balanced strings stays balanced, and the same string can be built in more than one way.
1
Designing a Recursive Set
Now we go the other way: given a set described in words, we want to find the Starters and Builder Machines that generate every valid object without ever building an invalid one.
Designing Your Own Recursive Set
Text solution
Positive integers with remainder 2 when divided by 5Starting at the smallest valid number 2, adding 5 steps to the next valid number while keeping the same remainder (unlike x+y, which fails because 2+2=4∈/S).
Starter: 2∈SMachine: If x∈S, then x+5∈S
Palindromes over {a,b}Gluing matching letters onto both ends keeps the string symmetric, and because each machine adds 2 letters at a time, the Starter Pack needs the empty string λ for even lengths along with a and b for odd centers.
Starters: λ,a,b∈PMachines: If x∈P, then axa∈Pand bxb∈P
Bit strings with no 11Appending 0 never creates 11, and appending 01 places a 0 between the old string and the new 1 so two 1s never touch; 1 must be a starter alongside λ because 1 is valid but doesn't end in 0 or 01.
Starters: λ,1∈SMachines: If x∈S, then x0∈Sand x01∈S
Because both palindrome machines add two letters to the outside without changing the middle, λ generates only the even-length palindromes while a and b start all the odd-length palindromes.
Adding matching letters to the outside never changes a palindrome's center, so each starter builds its own separate family of palindromes.
2
Proving Properties with Structural Induction
To prove that every object in a recursively defined set S has a certain property, we can't go through them in a single line n=1,2,3,… when they branch or combine two old objects at once. Instead, we check the starters and the machines directly using structural induction.
Inspecting the Factory: Structural Induction
Now let's turn that factory check into a written proof for numbers and strings.
Writing Structural Induction Proofs
Text solution
Check the starters (6,15∈S are multiples of 3)Factor 3 out of each starter to verify the base case.
6=3(2)and15=3(5)
Test the machines on any multiples of 3Assume x=3a and y=3b for some integers a and b, and factor 3 out of both machine outputs (plugging in 6+15=21 only checks Generation 1).
x+yx−y=3a+3b=3(a+b)=3a−3b=3(a−b)
Since a+b and a−b are integers, every number in S is a multiple of 3.
Check the starter and machines for balanced parentheses (L(x)=R(x))Verify that () has one of each, then assume L(x)=R(x) and L(y)=R(y) and substitute into the counts for (x) and xy.
Both machines keep the counts equal, so L(x)=R(x) for every x∈P.
3
Proving a Factory Builds Everything
Structural induction only proves that every item the factory builds belongs to the target set M(S⊆M). To prove that a recursively defined set S equals M without leaving any target items out (S=M), we also have to prove that the factory builds everything in M(M⊆S).
Proving a Factory Builds Everything
Text solution
Direction 1 (S⊆M by structural induction on S)The starter 3=3(1) is in M={3n∣n∈Z+}, and for any x=3a and y=3b with a,b∈Z+, the machine output stays a positive multiple of 3.
x+y=3a+3b=3(a+b)∈M
Direction 2 (M⊆S by ordinary induction on n≥1)For n=1,3(1)=3∈S by the Starter rule; assuming 3k∈S for some k≥1, rewrite 3(k+1) to feed 3k∈S and the starter 3∈S into the addition machine.
3(k+1)=∈S (IH)3k+∈S (Starter)3∈S
Since S⊆M and M⊆S, we have S=M.
4
Recursive Functions on Trees
To count features of a full binary tree, such as its leaves L(T), internal branching dots I(T), or height H(T), without relying on a drawing, we define each function on the same starter ∙ and machine join(T1,T2) that build the trees.
Prove L(T)=I(T)+1 (starter and machine)Check L(∙)=1=0+1=I(∙)+1, then assume the formula holds for T1 and T2 and regroup the sum to match I(join(T1,T2)).
Prove L(T)≤2H(T) (bound both exponents by their maximum)Check L(∙)=1≤20=2H(∙), then assume L(T1)≤2H(T1) and L(T2)≤2H(T2) and replace both exponents with max(H(T1),H(T2)) so the two powers of 2 can be combined.
Splitting any leaf adds one leaf and one internal dot so L(T)=I(T)+1 always holds, whereas L(T) only reaches 2H(T) when every branch grows to the same depth and drops below 2H(T) whenever the tree is lopsided.
Splitting a leaf adds one internal dot and one extra leaf, keeping leaves one ahead of internal dots, while only trees with every leaf on the bottom row hit the leaf limit for their height.
Key concepts
When objects line up in a single list by position n (like 2n or an=an−1+2), a direct formula or sequence is all you need. Use a recursively defined set when objects nest or branch in multiple ways, such as balanced parentheses (() with machines (x) and xy) or full binary trees (∙ with machine join(T1,T2)).
Designing a recursive set from words
Pick the smallest valid pieces to attach in your Builder Machines (like x⇒x0 and x⇒x01 to avoid 11), then peel those steps backward to find every valid object that cannot be broken down. All of those must go in the Starter Pack (λ and 1 for no-11;λ,a,b for palindromes under x⇒axa,bxb). Always test your machines on the starters to make sure they don't build invalid items (like x+y turning 2 and 2 into 4).
Proving every built item has a property (S⊆M)
Use structural induction on the factory rules. Check each starter in the base case, then assume arbitrary inputs x,y∈S satisfy the property (like x=3a,y=3b) and show each machine's output satisfies it too.
Proving the factory builds everything (M⊆S)
Do not use structural induction here, because structural induction works even on an incomplete set like Starter 6 with Machine x+y. Instead, use ordinary or strong induction on the index or size n of items in M to show how each target item is built from earlier items and the starters (such as rewriting 3(k+1)=3k+3).
Proving tree formulas with recursive functions
Substitute the starter values at ∙ and the machine rules at join(T1,T2) directly into the algebra; for height bounds, replace H(T1) and H(T2) with max(H(T1),H(T2)) to combine 2max+2max into 21+max=2H(join(T1,T2)).
5
Practice
1
A set S of integers is defined recursively by:
Starter: 2∈S.
Machine 1: If x∈S, then 3x∈S.
Machine 2: If x∈S, then x−1∈S.
List all numbers in S at Generation 0, the new numbers added in Generation 1, and the new numbers added in Generation 2. Then give a step-by-step sequence of machine operations that builds 14.
Apply both machines to every number from the previous generation, and to build 14, work backward from 14 by asking which machine must have been used last (since 14 is not a multiple of 3).
Generation 0 (the starter): 2.
Generation 1 (applying each machine once to 2): 3(2)=6 and 2−1=1, so the new numbers are 1 and 6.
Generation 2 (applying each machine to both 1 and 6; watch out for applying a machine to only one of them, or combining both machines in a single step like 3(1)−1=2): from 1 we get 3(1)=3 and 1−1=0; from 6 we get 3(6)=18 and 6−1=5. The new numbers are 0,3,5,18.
To build 14: start with 2∈S, run Machine 1 to get 3(2)=6∈S, run Machine 2 to get 6−1=5∈S, run Machine 1 to get 3(5)=15∈S, and run Machine 2 to get 15−1=14∈S.
2
Design a recursive definition (Starters and Builder Machines) for the set S of all bit strings over {0,1}, including the empty string λ, in which every 0 is immediately followed by a 1. Explain why your Starter Pack does not need any single-character string, unlike our recursive definition for bit strings with no 11.
Ask which single bit (0 or 1) can always be glued onto the right end of a valid string without leaving a lone 0, and what two-bit block includes a 0 followed by a 1.
Starter: λ∈S.
Machine 1: If x∈S, then x1∈S.
Machine 2: If x∈S, then x01∈S.(Watch out for writing x10 instead of x01:x10 leaves a 0 at the right end with no 1 after it! Also watch out for putting 0 or 1 in the Starter Pack out of habit: 0 is not a valid string in S, and 1 is already built from λ by Machine 1.)
Appending 1 or 01 to the right end of a valid string never leaves a 0 without a 1 immediately after it. Going the other way, any non-empty string in S cannot end in 0, so it must end in 1 (either preceded by 0, or not); peeling off 01 or 1 from the right end always leaves a shorter valid string in S, eventually reaching λ. For bit strings with no 11,1 had to be a starter because 1 is valid and cannot be formed by appending 0 or 01, whereas here 1 is built from λ by Machine 1 and 0∈/S.
3
A set S of integers is defined recursively by:
Starters: 1∈S and 5∈S.
Machine 1: If x∈S and y∈S, then x+y−1∈S.
Machine 2: If x∈S, then 3x−2∈S.
Prove by structural induction that every number in S leaves a remainder of 1 when divided by 4 (that is, for every x∈S,x=4k+1 for some integer k).
In the inductive step, write the arbitrary inputs as x=4a+1 and y=4b+1 for integers a and b, then simplify each machine's output into the form 4(integer)+1.
ClaimFor every x∈S,x=4k+1 for some integer k.
Base case (Starters)For 1,1=4(0)+1 with 0∈Z. For 5,5=4(1)+1 with 1∈Z. Both starters satisfy the claim.
Inductive step (Machines)Assume x,y∈S satisfy the claim, so x=4a+1 and y=4b+1 for some integers a and b.(Do not plug in the starters 1+5−1=5 and 3(5)−2=13, which only checks Generation 1, and don't drop the −1 in Machine 1, which would give 4(a+b)+2.)
For Machine 1:
x+y−1=(4a+1)+(4b+1)−1=4(a+b)+1
Since a+b is an integer, x+y−1 has the form 4k+1.
For Machine 2:
3x−2=3(4a+1)−2=12a+1=4(3a)+1
Since 3a is an integer, 3x−2 has the form 4k+1.
By structural induction, every x∈S is of the form 4k+1 for some integer k.
4
A set S of strings over the alphabet {a,b} is defined recursively by:
Starter: a∈S.
Machine 1: If x∈S, then abx∈S.
Machine 2: If x∈S and y∈S, then bxy∈S.
For any string w∈S, let A(w) be the number of a's in w and B(w) be the number of b's in w. Prove by structural induction that A(w)=B(w)+1 for every w∈S.
Express A(abx),B(abx),A(bxy), and B(bxy) in terms of the counts for x and y, then substitute the inductive hypothesis A(x)=B(x)+1 and A(y)=B(y)+1.
ClaimFor every w∈S,A(w)=B(w)+1.
Base case (Starter)For w=a,A(a)=1 and B(a)=0. Since 1=0+1, the claim holds for the starter.
Inductive step (Machines)Assume x,y∈S satisfy A(x)=B(x)+1 and A(y)=B(y)+1.
For Machine 1 (abx): Gluing ab onto x adds one a and one b, so A(abx)=A(x)+1 and B(abx)=B(x)+1. By the inductive hypothesis,
A(abx)=(B(x)+1)+1=B(abx)+1.
For Machine 2 (bxy): Gluing b,x, and y gives A(bxy)=A(x)+A(y) and B(bxy)=B(x)+B(y)+1.(Watch out for forgetting the +1 from the leading b in bxy, which would make A(bxy) look like B(bxy)+2.) By the inductive hypothesis,
By structural induction, A(w)=B(w)+1 for every w∈S.
5
Let S be the set of integers defined recursively by:
Starter: 2∈S.
Machine: If x∈S and y∈S, then x+y+3∈S.
Let M={5n−3∣n∈Z+} be the set of all positive integers that leave a remainder of 2 when divided by 5. Prove that S=M.
Split the proof into two directions: use structural induction on S to prove S⊆M, and ordinary induction on n≥1 to prove 5n−3∈S by rewriting 5(k+1)−3 so it matches the machine formula x+y+3.
We prove S⊆M and M⊆S.(Don't stop after proving S⊆M, since that only shows every built number is in M, not that every number in M gets built!)
Direction 1 (S⊆M, by structural induction on S)
ClaimFor every x∈S,x=5n−3 for some positive integer n.
Base caseThe starter is 2=5(1)−3, where n=1∈Z+, so 2∈M.
Inductive stepAssume x,y∈S are in M, so x=5a−3 and y=5b−3 for some a,b∈Z+. Then the machine produces
x+y+3=(5a−3)+(5b−3)+3=5(a+b)−3.
Since a+b∈Z+,x+y+3∈M. By structural induction, S⊆M.
Direction 2 (M⊆S, by ordinary induction on n≥1)
ClaimFor every integer n≥1,5n−3∈S.
Base case (n=1)5(1)−3=2∈S by the Starter rule.
Inductive stepAssume 5k−3∈S for some integer k≥1. We must show 5(k+1)−3∈S. Rewrite 5(k+1)−3 to match the machine rule x+y+3:
5(k+1)−3=(5k−3)+5=(5k−3)+2+3.
(Watch out for stopping at (5k−3)+5 and claiming 5∈S:5 is not in S, and the machine adds x+y+3, not x+y!) Since 5k−3∈S by the inductive hypothesis and 2∈S by the Starter rule, feeding x=5k−3 and y=2 into the machine x+y+3 gives (5k−3)+2+3=5(k+1)−3∈S. By ordinary induction, M⊆S.
Since S⊆M and M⊆S, we conclude that S=M.
6
On the set of full binary trees (Starter: a single dot ∙; Machine: join(T1,T2)), the total number of dots N(T) is defined recursively by N(∙)=1 and N(join(T1,T2))=N(T1)+N(T2)+1, and the height H(T) is defined by H(∙)=0 and H(join(T1,T2))=1+max(H(T1),H(T2)). Prove by structural induction that for every full binary tree T,
N(T)≤2H(T)+1−1.
After substituting the inductive hypothesis into N(T1)+N(T2)+1, notice how −1−1+1 simplifies to −1, and bound both exponents using max(H(T1),H(T2)).
ClaimFor every full binary tree T,N(T)≤2H(T)+1−1.
Base case (Starter ∙)By definition, N(∙)=1 and 2H(∙)+1−1=20+1−1=1. Since 1≤1, the inequality holds for ∙.
Inductive step (Machine join(T1,T2))Assume N(T1)≤2H(T1)+1−1 and N(T2)≤2H(T2)+1−1. By the recursive definition of N and the inductive hypothesis (don't forget the +1 for the new top dot in N(join(T1,T2))=N(T1)+N(T2)+1, which cancels one of the −1s to leave −1 instead of −2):