CSE 311: Foundations of Computing
Fall 2013
Lecture 17: Recursive definitions and structural induction
announcements
Reading assignment
Induction
5.3, 7th edition
4.3, 6th edition
Homework 5 solutions out today
Midterm
Monday, November 4th, IN CLASS
Topics: Everything up to ordinary induction and
recursive definition of functions
Sample questions from old midterms now posted.
Solutions posted later today.
Review sessions: Today 3:30, Sunday 4:00 in EEB 125
review: recursive definition of sets
Recursive definition
– Basis step: 0∈
– Recursive step: if ∈ , then + 2∈
– Exclusion rule: Every element in follows from
basis steps and a finite number of recursive
steps
review: recursive definitions of sets
Basis:
Recursive:
Basis:
Recursive:
6 ∈ ; 15 ∈ ;
if , ∈ , then + ∈ ;
1, 1, 0 ∈ , 0, 1, 1 ∈ ;
if , , ∈ , ∈ ℝ, then α , ,
∈
if [ 1, 1, 1], [ 2, 2, 2]∈ then [ 1 + 2, 1 + 2, 1 + 2]∈
Powers of 3: 1 ∈
and
∈ ⇒3 ∈
recursive definitions of sets: general form
review: strings
Recursive definition
– Basis step: Some specific elements are in
– Recursive step: Given some existing named
elements in some new objects constructed
from these named elements are also in .
– Exclusion rule: Every element in follows from
basis steps and a finite number of recursive
steps
• An alphabet Σ is any finite set of characters
review: palindromes
review: all binary strings with no 1’s before 0’s
Palindromes are strings that are the same
backwards and forwards
Basis:
λ is a palindrome and any ∈ Σ is a palindrome
Recursive step:
If ∈ Σ ∗ is a palindrome then
palindrome for every ∈ Σ
is a
• The set Σ* of strings over the alphabet Σ is
defined by
– Basis: λ ∈ Σ* (λ is the empty string)
– Recursive: if ∈ Σ*, ∈ Σ, then
∈ Σ*
function definitions on recursively defined sets
len (λ) = 0;
len ( ) = 1 + len( ); for
∗
∈Σ ,
∈Σ
rooted binary trees
• Basis: • is a rooted binary tree
• Recursive step: If
Reversal:
=
=
for
∈ Σ*,
∈Σ
Concatenation:
• λ = for ∈ Σ*
• = ( • ) for , ∈Σ*, ∈Σ
and
T1
T2
rooted binary trees
then so is:
T1
functions defined on rooted binary trees
structural induction
• size(•)=1
How to prove ∀ ∈ , ( )is true:
• size(
T1
T2
) = 1+size(T1)+size(T2)
• height(•)=0
• height( T
1
T2
)=1+max{height(T1),height(T2)}
are
T2
– Base Case: Show that is true for all specific
elements of mentioned in the Basis step
– Inductive Hypothesis: Assume that is true for
some arbitrary values of each of the existing named
elements mentioned in the Recursive step
– Inductive Step: Prove that holds for each of the
new elements constructed in the Recursive step using
the named elements mentioned in the Inductive
Hypothesis
– Conclude that ∀ ∈ , ( )
structural induction vs. ordinary induction
using structural induction
Ordinary induction is a special case of structural
induction:
Recursive definition of ℕ
Basis: 0 ∈!
Recursive Step: If k ∈! then k+1 ∈!
• Let be given by
– Basis:
6∈ ; 15 ∈ ;
– Recursive: if , ∈ , then + ∈ .
• Claim: Every element of is divisible by 3.
Structural induction follows from ordinary induction:
Let "(#) be true iff for all ∈ that take
#recursive steps to be constructed, ( ) is true.
Claim: Every element of
is divisible by 3.
structural induction for strings
• Let be a set of strings over { , %}defined as
follows
– Basis: ∈
– Recursive:
If ∈ then
∈ and %
If ' ∈ and ( ∈ then '( ∈
• Claim: If
∈ then
∈
has more ’s than %’s
Claim: If
∈ then
has more ’s than %’s
Basis: ∈ Recursive: If ∈ then
∈ and %
If ' ∈ and ( ∈ then '( ∈
function definitions on recursively defined sets
len (λ) = 0;
len ( ) = 1 + len( ); for
∈
∈ Σ∗,
∈Σ
Reversal:
=
=
for
∈ Σ*,
∈Σ
Concatenation:
• λ = for ∈ Σ*
• = ( • ) for , ∈Σ*, ∈Σ
len( • ) = len( ) + len( )for all strings
and
Let ( )be “len( • ) = len( ) + len( ) for all strings ”
len( • ) = len( ) + len( )for all strings
and
Let ( )be “len( • ) = len( ) + len( ) for all strings ”
functions defined on rooted binary trees
• size(•)=1
• size(
T1
T2
) = 1+size(T1)+size(T2)
• height(•)=0
• height( T
1
T2
)=1+max{height(T1),height(T2)}
For every rooted binary tree ,, -. /(,) ≤ 2123415(6)78 − 1
For every rooted binary tree ,, -. /(,) ≤ 2123415(6)78 − 1
© Copyright 2026 Paperzz