Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 311: Foundations of Computing

Similar presentations


Presentation on theme: "CSE 311: Foundations of Computing"β€” Presentation transcript:

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


Download ppt "CSE 311: Foundations of Computing"

Similar presentations


Ads by Google