CSE 311: Foundations of Computing announcements Fall 2013 Reading - - PowerPoint PPT Presentation

cse 311 foundations of computing announcements
SMART_READER_LITE
LIVE PREVIEW

CSE 311: Foundations of Computing announcements Fall 2013 Reading - - PowerPoint PPT Presentation

CSE 311: Foundations of Computing announcements Fall 2013 Reading assignment Lecture 17: Recursive definitions and structural induction Induction 5.3, 7 th edition 4.3, 6 th edition Homework 5 solutions out today Midterm Monday, November 4 th


slide-1
SLIDE 1

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: 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 ∈

slide-2
SLIDE 2

recursive definitions of sets: general form

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

review: strings

  • An alphabet Σ

Σ Σ Σ is any finite set of characters

  • The set Σ

Σ Σ Σ* * * * of strings over the alphabet Σ Σ Σ Σ is defined by – Basis: Basis: Basis: Basis: λ ∈ Σ* (λ is the empty string) – Recursive: Recursive: Recursive: Recursive: if ∈ Σ*, ∈ Σ, then ∈ Σ*

review: palindromes

Palindromes are strings that are the same backwards and forwards Basis: Basis: Basis: Basis: λ is a palindrome and any ∈ Σ is a palindrome Recursive step: Recursive step: Recursive step: Recursive step: If ∈ Σ∗ is a palindrome then is a palindrome for every ∈ Σ

review: all binary strings with no 1’s before 0’s

slide-3
SLIDE 3

function definitions on recursively defined sets

len (λ) = 0; len () = 1 + len(); for ∈ Σ∗, ∈ Σ Reversal: = = for ∈ Σ*, ∈ Σ Concatenation:

  • λ = for ∈ Σ*
  • = ( • ) for , ∈ Σ*, ∈ Σ

rooted binary trees

  • Basis:

Basis: Basis: Basis: • is a rooted binary tree

  • Recursive step:

Recursive step: Recursive step: Recursive step: If and are rooted binary trees then so is: T1 T2 T1 T2 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

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 ∀ ∈ , ()

slide-4
SLIDE 4

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.

using structural induction

  • Let be given by

– Basis: Basis: Basis: Basis: 6 ∈ ; 15 ∈ ; – Recursive: Recursive: Recursive: Recursive: if , ∈ , then + ∈ .

  • Claim:

Claim: Claim: Claim: Every element of is divisible by 3. Claim: Claim: Claim: 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
slide-5
SLIDE 5

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 ”

slide-6
SLIDE 6

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

For every rooted binary tree ,, -./(,) ≤ 2123415(6)78 − 1 For every rooted binary tree ,, -./(,) ≤ 2123415(6)78 − 1