Structural
Induction
Cardinality
Warm-Up
How Big is a Set?
1/18/12%
Harry%Lewis/CS20/CSCI%E4120/with%thanks%
to%Albert%
R.%
Meyer%
1%
“Balanced String of Parentheses”
• Base case:
– The empty string εis balanced
• Constructor Cardinality
rules:
– C1: If x is balanced then so is (x), that is, the
result of writing a “(“, then x, then “)”
How Big is a Set?
– C2: If x and y are balanced then so is xy
1/18/12%
Harry%Lewis/CS20/CSCI%E4120/with%thanks%
to%Albert%
R.%
Meyer%
1%
A String of Parentheses is Balanced iff
it Satisfies the Counting Rule (SCR)
• Say that a string s∈{ ), ( }* SCR iff starting
from 0 at the left end of the string, adding
1 for each (, Cardinality
subtracting 1 for each ), gives
0 at the end without ever going negative.
• Theorem: A string of parentheses is
How Big is a Set?
balanced iff it SCR.
1/18/12%
Harry%Lewis/CS20/CSCI%E4120/with%thanks%
to%Albert%
R.%
Meyer%
1%
If a string of parentheses x is
balanced, then x SCR.
• Structural Induction Base case: x=ε. Then
count begins and ends 0 so x SCR.
• Induction case 1: x = (y) where y is balanced.
Cardinality
Then y SCR (why?).
Then the count for x is
+1 after first (, +1 again after the last
character of y, stays positive in between, and
ends at 0 after
theBig
final
How
is).a Set?
• Induction case 2: x = yz where y and z are
balanced. Then y and z SCR and the count
goes from 0, to 0 after y, to 0 after z without
ever going negative.
1/18/12%
Harry%Lewis/CS20/CSCI%E4120/with%thanks%
to%Albert%
R.%
Meyer%
1%
If x SCR then x is balanced.
• Proof by strong induction on |x|. Suppose x SCR.
• Base case: |x|=0. Then x=εand x is balanced.
• Induction step. Fix n, suppose |x| = n+1>0 and for all
m≤n and any y of length m, if y SCR then y is balanced.
• Case 1. The count never reaches 0 except at the end.
Then x=(y) where y SCR (why?). But |y|=|x|-2 and by IH
How
Big is arule
Set?
y is balanced. By
construction
1 so is x.
• Case 2. x=yz where the y and z are nonempty and the
count goes to 0 after y. Then y and z are shorter than x
and each SCR, so each is balanced by IH. Then x is
balanced by construction rule 2.
Cardinality
1/18/12%
Harry%Lewis/CS20/CSCI%E4120/with%thanks%
to%Albert%
R.%
Meyer%
1%
TEAM PROBLEMS
Cardinality
How Big is a Set?
1/18/12%
Harry%Lewis/CS20/CSCI%E4120/with%thanks%
to%Albert%
R.%
Meyer%
1%
© Copyright 2026 Paperzz