Download presentation
Presentation is loading. Please wait.
1
and Structural Induction
Mathematics for Computer Science MIT 6.042J/18.062J Recursive Definitions and Structural Induction Copyright © Albert Meyer, 2002. Prof. Albert Meyer & Dr. Radhika Nagpal
2
Build something from a simpler version of the same thing:
Recursive Definitions Build something from a simpler version of the same thing: Base case(s) that don’t depend on anything else Induction (Construction) case(s) that depend on simpler cases
3
Example Definition: set E
Define set E Z, recursively: 0 E Base Case
4
Example Definition: set E
Define set E Z, recursively: 0 E Base Case E : 0
5
Example Definition: set E
Define set E Z, recursively: 0 E Base Case If n E, then n + 2 E Induction case If n E, then -n E Induction case E : 0 , 0+2
6
Example Definition: set E
Define set E Z, recursively: 0 E If n E, then n + 2 E If n E, then -n E E : 0, 2, 2+2 , (2+2)+2
7
Example Definition: set E
Define set E Z, recursively: 0 E If n E, then n + 2 E If n E, then -n E E : 0, 2, 4, 6, … All even numbers Also, , -4, -6, …
8
Example Definition: set E
So, E contains the even integers
9
Example Definition: set E
So, E contains the even integers Anything Else?
10
Example Definition: set E
So, E contains the even integers Anything Else? No!
11
Recursive Definition: Extremal Clause
So, E contains the even integers Anything Else? No! 0 E If n E, then n + 2 E If n E, then -n E
12
Recursive Definition: Extremal Clause
So, E contains the even integers Anything Else? No! 0 E If n E, then n + 2 E If n E, then -n E Implicit part of recursive definition: THAT’S ALL!
13
Example Definition: set E
So E is exactly: The Even Integers
14
Define set of strings, S {a, b}*
Another Example Define set of strings, S {a, b}* l S, (the empty string) If x, y S, then the following are in S: axb bxa xy
15
Proof by Structural Induction on S
Lemma: Every x in S has an equal number of a’s and b’s.
16
Structural Induction on S
Proof: Let EQ ::= {strings with equal # of a’s and b’s} P(s) ::= s S s EQ
17
Structural Induction on S
Proof: Let EQ ::= {strings with equal # of a’s and b’s} P(s) ::= s S s EQ Base Case: s = l. 0 a’s and 0 b’s. OK
18
Structural Induction on S
Inductive Step: Assume: P(x) and P(y) To Prove: P(axb), P(bxa), and P(xy)
19
Structural Induction on S
Inductive Step: Assume: P(x) and P(y) To Prove: P(axb), P(bxa), and P(xy) Case 1: axb has k + 1 a’s and b’s if x has k of each. OK
20
Structural Induction on S
Inductive Step: Assume: P(x) and P(y) To Prove: P(axb), P(bxa), and P(xy) Case 2: bxa SAME
21
Structural Induction on S
Inductive Step: Assume: P(x) and P(y) To Prove: P(axb), P(bxa), and P(xy) Case 3: xy has kx + ky of each. OK
22
Theorem: S = EQ Show by strong induction on length of string in EQ.
Proof in Notes 5.
23
In-Class Problem Problem 1
24
Recursive Data Types Rooted Binary Trees
25
Defined recursively as follows: A single node r is in T:
Rooted Binary Trees Defined recursively as follows: A single node r is in T:
26
t t t t’ Rooted Binary Trees
If t, t’ are RBTs, then the following are RBTs Makeleft(t) t Makeright(t) t Makeboth(t,t’) t t’
27
A Rooted Binary Tree Example
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.