cse 311 foundations of computing announcements
play

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


  1. 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 , 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 review: recursive definitions of sets Basis: 6 ∈ �; 15 ∈ �; Recursive definition if �, � ∈ � , then � + � ∈ � ; Recursive: – Basis step: 0 ∈ � – Recursive step: if � ∈ � , then � + 2 ∈ � 1, 1, 0 ∈ �, 0, 1, 1 ∈ �; Basis: – Exclusion rule: Every element in � follows from Recursive: basis steps and a finite number of recursive steps if �, �, � ∈ �, � ∈ ℝ , then α �, ��, �� ∈ � if [� 1 , � 1 , � 1 ], [� 2 , � 2 , � 2 ] ∈ � then [� 1 + � 2 , � 1 + � 2 , � 1 + � 2 ] ∈ � Powers of 3: 1 ∈ � and � ∈ � ⇒ 3� ∈ �

  2. recursive definitions of sets: general form review: strings Recursive definition • An alphabet Σ Σ is any finite set of characters Σ Σ – Basis step: Some specific elements are in � – Recursive step: Given some existing named • The set Σ Σ * * of strings over the alphabet Σ * * Σ is Σ Σ Σ Σ elements in � some new objects constructed defined by from these named elements are also in � . – Basis: Basis: Basis: Basis: λ ∈ Σ * ( λ is the empty string) – Exclusion rule: Every element in � follows from – Recursive: Recursive: Recursive: Recursive: if � ∈ Σ *, � ∈ Σ , then �� ∈ Σ * basis steps and a finite number of recursive steps review: palindromes review: all binary strings with no 1’s before 0’s 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 � ∈ Σ

  3. function definitions on recursively defined sets rooted binary trees • Basis: Basis: • is a rooted binary tree Basis: Basis: len ( λ ) = 0; len ( �� ) = 1 + len( � ); for � ∈ Σ ∗ , � ∈ Σ • Recursive step: Recursive step: Recursive step: Recursive step: If and are Reversal: � � = � T 1 T 2 �� � = �� � for � ∈ Σ *, � ∈ Σ rooted binary trees Concatenation: � • λ = � for � ∈ Σ * then so is: � • �� = (� • �)� for �, � ∈ Σ *, � ∈ Σ T 1 T 2 functions defined on rooted binary trees structural induction How to prove ∀ � ∈ �, (�) is true: • size(•)=1 – Base Case: Show that is true for all specific elements of � mentioned in the Basis step • size( ) = 1+size(T 1 )+size(T 2 ) – Inductive Hypothesis: Assume that is true for T 1 T 2 some arbitrary values of each of the existing named elements mentioned in the Recursive step – Inductive Step: Prove that holds for each of the • height(•)=0 new elements constructed in the Recursive step using the named elements mentioned in the Inductive Hypothesis • height( )=1+max{height(T 1 ),height(T 2 )} – Conclude that ∀ � ∈ �, (�) T 1 T 2

  4. using structural induction structural induction vs. ordinary induction Ordinary induction is a special case of structural • Let � be given by induction: 6 ∈ �; 15 ∈ �; – Basis: Basis: Basis: Basis: Recursive definition of ℕ Recursive: if �, � ∈ � , then � + � ∈ � . – Recursive: Recursive: Recursive: Basis: 0 ∈ ! • Claim: Claim: Claim: Claim: Every element of � is divisible by 3 . 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. Claim: Every element of � is divisible by 3 . Claim: Claim: Claim: 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

  5. Claim: If � ∈ � then � has more � ’s than % ’s function definitions on recursively defined sets Basis: � ∈ � len ( λ ) = 0; Recursive: If � ∈ � then �� ∈ � and %�� ∈ � len ( �� ) = 1 + len( � ); for � ∈ Σ ∗ , � ∈ Σ If ' ∈ � and ( ∈ � then '( ∈ � Reversal: � � = � �� � = �� � for � ∈ Σ *, � ∈ Σ Concatenation: � • λ = � for � ∈ Σ * � • �� = (� • �)� for �, � ∈ Σ *, � ∈ Σ len(� • �) = len(�) + len(�) for all strings � and � len(� • �) = len(�) + len(�) for all strings � and � Let (�) be “ len(� • �) = len(�) + len(�) for all strings � ” Let (�) be “ len(� • �) = len(�) + len(�) for all strings � ”

  6. For every rooted binary tree , , -.�/(,) ≤ 2 123415(6)78 − 1 functions defined on rooted binary trees • size(•)=1 • size( ) = 1+size(T 1 )+size(T 2 ) T 1 T 2 • height(•)=0 • height( )=1+max{height(T 1 ),height(T 2 )} T 1 T 2 For every rooted binary tree , , -.�/(,) ≤ 2 123415(6)78 − 1

Recommend


More recommend