Download presentation
Presentation is loading. Please wait.
1
CSE 311: Foundations of Computing
Fall 2013 Lecture 17: Recursive definitions and structural induction
2
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
3
review: recursive definition of sets
Basis step: 0 ο π Recursive step: if π₯ ο π, then π₯+2 ο π Exclusion rule: Every element in π follows from basis steps and a finite number of recursive steps
4
review: recursive definitions of sets
Basis: 6βπ; 15βπ; Recursive: if π₯, π¦ ο π, then π₯ + π¦ ο π; Basis: 1, 1, 0 ο π, 0, 1, 1 οπ; Recursive: if π₯, π¦, π§ ο π, πΌβ β, then ο‘π₯, πΌπ¦, πΌπ§ βπ if [π₯1, π¦1, π§1], [π₯2, π¦2, π§2] ο π then [π₯1 + π₯2, π¦1 + π¦2, π§1 + π§2] ο π Powers of 3: 1βπ and π₯βπ 3π₯βπ
5
recursive definitions of sets: general form
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
6
review: strings An alphabet ο is any finite set of characters
The set ο* of strings over the alphabet ο is defined by Basis: ο¬ ο ο* (ο¬ is the empty string) Recursive: if π€ ο ο*, π ο ο, then π€π ο ο*
7
review: palindromes 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 πππ is a palindrome for every πβ ο
8
review: all binary strings with no 1βs before 0βs
9
function definitions on recursively defined sets
len (ο¬) = 0; len (π€π) = 1 + len(π€); for π€β Ξ£ β , πβΞ£ Reversal: π π
=π π€π π
= ππ€ π
for π€ ο ο*, π ο ο Concatenation: π₯ β’ ο¬ = π₯ for π₯ ο ο* π₯ β’ π€π = (π₯ β’ π€)π for π₯, π€ ο ο*, π ο ο
10
rooted binary trees Basis: β’ is a rooted binary tree Recursive step: If and are rooted binary trees then so is: T2 T1 T2 T1
11
functions defined on rooted binary trees
size(β’)=1 size( ) = 1+size(T1)+size(T2) height(β’)=0 height( )=1+max{height(T1),height(T2)} T1 T2 T1 T2
12
structural induction How to prove ο’π₯βπ, π(π₯) is true:
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 ο’π₯βπ, π(π₯)
13
structural induction vs. ordinary induction
Ordinary induction is a special case of structural induction: Recursive definition of β Basis: 0 β β Recursive Step: If k β β then k+1 β β Structural induction follows from ordinary induction: Let π(π) be true iff for all π₯βπ that take π recursive steps to be constructed, π(π₯) is true.
14
using structural induction
Let π be given by Basis: 6 ο π; 15β π; Recursive: if π₯, π¦βπ, then π₯ + π¦βπ. Claim: Every element of π is divisible by 3.
15
Claim: Every element of π is divisible by 3.
16
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
17
Claim: If π€βπ then π€ has more πβs than πβs
Basis: πβπ Recursive: If π€βπ then ππ€βπ and πππ€βπ If π’βπ and π£βπ then π’π£βπ
18
function definitions on recursively defined sets
len (ο¬) = 0; len (π€π) = 1 + len(π€); for π€β Ξ£ β , πβΞ£ Reversal: π π
=π π€π π
= ππ€ π
for π€ ο ο*, π ο ο Concatenation: π₯ β’ ο¬ = π₯ for π₯ ο ο* π₯ β’ π€π = (π₯ β’ π€)π for π₯, π€ ο ο*, π ο ο
19
len(π₯β’π¦)=len(π₯)+len(π¦) for all strings π₯ and π¦
Let π(π¦) be βlen(π₯β’π¦)=len(π₯)+len(π¦) for all strings π₯β
20
len(π₯β’π¦)=len(π₯)+len(π¦) for all strings π₯ and π¦
Let π(π¦) be βlen(π₯β’π¦)=len(π₯)+len(π¦) for all strings π₯β
21
functions defined on rooted binary trees
size(β’)=1 size( ) = 1+size(T1)+size(T2) height(β’)=0 height( )=1+max{height(T1),height(T2)} T1 T2 T1 T2
22
For every rooted binary tree π, π ππ§π(π)β€ 2 βπππβπ‘(π)+1 β1
23
For every rooted binary tree π, π ππ§π(π)β€ 2 βπππβπ‘(π)+1 β1
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.