Announcements. CS243: Discrete Structures. Strong Induction and Recursively Defined Structures. Review. Example (review) Example (review), cont.

Similar documents
Recursively Defined Functions

1KOd17RMoURxjn2 CSE 20 DISCRETE MATH Fall

Mathematical Induction

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010

Computer Science 236 Fall Nov. 11, 2010

Recursive Definitions Structural Induction Recursive Algorithms

Lecture 3.4: Recursive Algorithms

CSE 20 DISCRETE MATH WINTER

MATH 54 - LECTURE 4 DAN CRYTSER

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences

Proof Techniques Alphabets, Strings, and Languages. Foundations of Computer Science Theory

Inference rule for Induction

Lamé s Theorem. Strings. Recursively Defined Sets and Structures. Recursively Defined Sets and Structures

Outline. Introduction. 2 Proof of Correctness. 3 Final Notes. Precondition P 1 : Inputs include

Solutions to the Second Midterm Exam

Recursion and Structural Induction

Chapter Summary. Mathematical Induction Recursive Definitions Structural Induction Recursive Algorithms

Fall Recursion and induction. Stephen Brookes. Lecture 4

Chapter Summary. Recursively defined Functions. Recursively defined sets and Structures Structural Induction

Mathematical Induction

AXIOMS FOR THE INTEGERS

Lecture 6,

CS 3410 Ch 7 Recursion

DVA337 HT17 - LECTURE 4. Languages and regular expressions

Lecture 15 : Review DRAFT

CS 310 Advanced Data Structures and Algorithms

CS 220: Discrete Structures and their Applications. Recursive objects and structural induction in zybooks

Discrete Mathematics Lecture 4. Harper Langston New York University

Array Dependence Analysis as Integer Constraints. Array Dependence Analysis Example. Array Dependence Analysis as Integer Constraints, cont

Material from Recitation 1

Notes for Comp 454 Week 2

Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103. Chapter 2. Sets

CSE 20 DISCRETE MATH. Winter

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

COT 3100 Spring 2010 Midterm 2

MATH 22 MORE ABOUT FUNCTIONS. Lecture M: 10/14/2003. Form follows function. Louis Henri Sullivan

Glynda, the good witch of the North

CMPSCI 250: Introduction to Computation. Lecture #1: Things, Sets and Strings David Mix Barrington 22 January 2014

CSE 20 DISCRETE MATH. Fall

Ambiguous Grammars and Compactification

CS250: Discrete Math for Computer Science. L20: Complete Induction and Proof of Euler s Characterization of Eulerian-Walks

CMPSCI 250: Introduction to Computation. Lecture #14: Induction and Recursion (Still More Induction) David Mix Barrington 14 March 2013

APCS-AB: Java. Recursion in Java December 12, week14 1

Logic and Computation Lecture 20 CSU 290 Spring 2009 (Pucella) Thursday, Mar 12, 2009

(a) (4 pts) Prove that if a and b are rational, then ab is rational. Since a and b are rational they can be written as the ratio of integers a 1

If you are going to form a group for A2, please do it before tomorrow (Friday) noon GRAMMARS & PARSING. Lecture 8 CS2110 Spring 2014

To illustrate what is intended the following are three write ups by students. Diagonalization

Fundamental mathematical techniques reviewed: Mathematical induction Recursion. Typically taught in courses such as Calculus and Discrete Mathematics.

Strategies for Proofs

CSCI 136 Data Structures & Advanced Programming. Lecture 9 Fall 2018 Instructors: Bills

Chapter 3. Set Theory. 3.1 What is a Set?

Math 302 Introduction to Proofs via Number Theory. Robert Jewett (with small modifications by B. Ćurgus)

Slides for Faculty Oxford University Press All rights reserved.

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

Solutions to Homework 10

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Approximation algorithms Date: 11/18/14

1 Elementary number theory

Compiler Construction

Recursion. Tjark Weber. Functional Programming 1. Based on notes by Sven-Olof Nyström. Tjark Weber (UU) Recursion 1 / 37

MATH20902: Discrete Maths, Solutions to Problem Set 1. These solutions, as well as the corresponding problems, are available at

Languages and Strings. Chapter 2

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic.

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

Homework 2. Sample Solution. Due Date: Thursday, May 31, 11:59 pm

2 Geometry Solutions

CT32 COMPUTER NETWORKS DEC 2015

Solution for Homework set 3

Lecture 3: Recursion; Structural Induction

Integers and Mathematical Induction

Sets and set operations. Lecture 5 ICOM 4075

CSE 120. Computer Science Principles

Topology and Topological Spaces

University of Illinois at Chicago Department of Computer Science. Final Examination. CS 151 Mathematical Foundations of Computer Science Fall 2012

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

Types, Expressions, and States

Introduction. CS243: Discrete Structures. Combinatorics. Product Rule. Basic Counting Rules. Example 2. Example 1

Math Circle Beginners Group October 18, 2015 Solutions

Lemma (x, y, z) is a Pythagorean triple iff (y, x, z) is a Pythagorean triple.

Discrete Mathematics Introduction

CS 173 [A]: Discrete Structures, Fall 2012 Homework 8 Solutions

Announcements. Application of Recursion. Motivation. A Grammar. A Recursive Grammar. Grammars and Parsing

Admin. How's the project coming? After these slides, read chapter 13 in your book. Quizzes will return

Notes for Recitation 8

Introduction to Sets and Logic (MATH 1190)

1. (15 points) Solve the decanting problem for containers of sizes 199 and 179; that is find integers x and y satisfying.

CpSc 421 Final Solutions

EDAA40 At home exercises 1

Problem Set 2 Solutions

1. Chapter 1, # 1: Prove that for all sets A, B, C, the formula

Lexical Analysis. Sukree Sinthupinyo July Chulalongkorn University

Recursion. Lars-Henrik Eriksson. Functional Programming 1. Based on a presentation by Tjark Weber and notes by Sven-Olof Nyström

Lecture 25 : Counting DRAFT

Reading 8 : Recursion

Overview. A mathema5cal proof technique Proves statements about natural numbers 0,1,2,... (or more generally, induc+vely defined objects) Merge Sort

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion

Discrete Mathematics. Kruskal, order, sorting, induction

ECS 120 Lesson 7 Regular Expressions, Pt. 1

CMPSCI 250: Introduction to Computation. Lecture #28: Regular Expressions and Languages David Mix Barrington 2 April 2014

CS70: Discrete Math and Probability. Fan Ye June 23, 2016

Transcription:

Announcements CS43: Discrete Structures Strong Induction and Recursively Defined Structures Işıl Dillig Homework 4 is due today Homework 5 is out today Covers induction (last lecture, this lecture, and next lecture) Homework 5 due next Thursday Nov. 1 7 questions, all of them require proofs start early! Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 1/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures /34 Review Induction is used to prove universally quantified properties about natural numbers and other countably infinite sets Consists of a base case and inductive step prove property about the least element(s) Inductive step: assume P(k) and prove P(k + 1) The assumption that P(k) is true is called inductive hypothesis Example (review) Prove the following statement by induction: n n Z + (n)(n + 1). n = 1. In this case, 1 the base case holds. 1 and (1)(1+1) = 1; thus, Inductive step: By the inductive hypothesis, we assume P(k): k Now, we want to show P(k + 1): (k)(k + 1) (k + 1)(k + ) Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 3/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 4/34 Example (review), cont. Plan for Today First, observe: k i + (k + 1) By the inductive hypothesis, k (k)() ; thus: Strong induction Rewrite left hand side as: (k)(k + 1) + (k + 1) Recursive definitions Proving properties of recursively defined functions k + 3k + = (k + 1)(k + ) Since we proved both base case and inductive step, property holds. Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 5/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 6/34 1

Strong Induction Motivation for Strong Induction Strong induction is a proof technique that is a slight variation on matemathical (regular) induction Just like regular induction, have to prove base case and inductive step, but inductive step is slightly different Regular induction: assume P(k) holds and prove P(k + 1) Strong induction: assume P(1), P(),.., P(k); prove P(k + 1) Regular induction and strong induction are equivalent, but strong induction can sometimes make proofs easier Prove that if n is an integer greater than 1, then it is either a prime or can be written as the product of primes. Let s first try to prove the property using regular induction. Base case (n=): Since is a prime number, P() holds. Inductive step: Assume k is either a prime or the product of primes. But this doesn t really help us prove the property about k + 1! Claim is proven much easier using strong induction! Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 7/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 8/34 Proof Using Strong Induction Proof, cont. Prove that if n is an integer greater than 1, then it is either a prime or can be written as the product of primes. same as before. Inductive step: Assume each of, 3,..., k is either prime or product of primes. Now, we want to prove the same thing about k + 1 Two cases: k + 1 is either (i) prime or (ii) composite If it is prime, property holds. If composite, k + 1 can be written as pq where p, q k Because a composite number has a divisor distinct from 1 and itself By the IH, p, q are either primes or product of primes. Thus, k + 1 can also be written as product of primes Observe: Much easier to prove this property using strong induction! Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 9/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 10/34 A Word about Base Cases Example In all examples so far, we had only one base case i.e., only proved the base case for one integer In some inductive proofs, there may be multiple base cases i.e., prove base case for the first m numbers Perfectly fine to have inductive proofs with multiple base cases In such proofs, inductive step only needs to consider numbers greater than m Prove that every integer n 1 can be written as n = 4a + 5b for some non-negative integers a, b. Proof by strong induction on n and consider 4 base cases Base case 1 (n=1): Base case (n=13): Base case 3 (n=14): Base case 4 (n=15): Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 11/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 1/34

Example, cont. Prove that every integer n 1 can be written as n = 4a + 5b for some non-negative integers a, b. Inductive hypothesis: Suppose every 1 i k can be written as 4a + 5b. Inductive step: We want to show k + 1 can also be written this way for k + 1 16 Observe: k + 1 = (k 3) + 4 By IH, k 3 = 4a + 5b for some a, b because k 3 1 Recursive Definitions In this class, we saw how to define functions and sequences: f (n) = n an = 3n + 1 These are examples of direct (non-recursive) definitions But in some cases, it is easier to define functions/sets in terms of themselves rather than directly But then, k + 1 can be written as 4(a + 1) + 5b Would this proof work if we only showed base case for n = 1? Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 13/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 14/34 Recursive Definitions Recursive Definitions in Math Definitions of structures that refer to themselves are called recursive definitions Picture below is defined recursively because each picture containts a smaller version of itself Recursive definitions come up a lot in discrete math Consider the factorial function: n! = 1 3... n This is a direct definition, but easier to define factorial recursively: 1! = 1 n! = (n 1)! n Definition is recursive because we use! when defining! Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 15/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 16/34 General Structure of Recursive Definitions Recursively Defined Function Example Recursive definitions consist of base case and recursive step Base case defines function for least element in the domain Recursive step shows how to compute f (k + 1) assuming f (k) can be computed For factorial, base case is 1! = 1 For factorial, recursive step is n! = (n 1)! n Recursive definitions are similar to proofs by induction Here is another recursive definition: What is f (1)? What is f ()? What is f (3)? f (0) = 3 f (n + 1) = f (n) + 3 (n 1) In fact, recursive definitions sometimes called inductive definitions Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 17/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 18/34 3

Recursively Defined Sequences Recursive Definition Examples Just like functions, sequences can also be defined recursively For example, consider the following sequence: 1, 3, 9, 7, 81,... What is a recursive definition of this sequence? Consider f (n) = n + 1 where n is non-negative integer What s a recursive definition for f? Consider the sequence 1, 4, 9, 16,... What is a recursive definition for this sequence? Recursive definition of function defined as f (n) = n i? Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 19/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 0/34 Recursive Definitions of Important Functions Inductive Proofs for Recursively Defined Structures Some important functions/sequences defined recursively Factorial function: f (1) = 1 f (n) = n f (n 1) (n ) Fibonacci numbers: 0, 1, 1,, 3, 5, 8, 13, 1,... a 0 = 0 a 1 = 1 a n = a n 1 + a n (n ) Just like there can be multiple bases cases in inductive proofs, there can be multiple base cases in recursive definitions Recursive definitions and inductive proofs are very similar Therefore, it s natural to use induction to prove properties about recursively defined functions and sequences In these proofs, base case of induction shows property holds for base case of recursive definition Similarly, the inductive step shows the property holds for the recursive part of the definition Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 1/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures /34 Example 1 Example 1, cont. Consider the function defined recursively as follows: Prove that f (n) = 3n + 1 f (0) = 1 f (n) = f (n 1) + 3 We ll prove this by regular mathematical induction f (0) = 1 f (n) = f (n 1) + 3 Inductive step: We need to show f (k + 1) = 3(k + 1) + 1 assuming f (k) = 3k + 1 Using the recursive case of definition, f (k + 1) = f (k) + 3 From IH, f (k) = 3k + 1 Thus, f (k + 1) = 3k + 1 + 3 = 3(k + 1) + 1 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 3/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 4/34 4

Example Example, cont. Prove: For n 3, f n > α n where α = 1+ 5 Let f n denote the n th element of the Fibonacci sequence Prove: For n 3, f n > α n where α = 1+ 5 Proof is by strong induction on n with two base cases Base case 1 (n=3): f 3 =, and α <, thus f 3 > α Base case (n=4): f 4 = 3 and α = (3+ 5) < 3 Inductive step: We need to show f > α k 1 for k + 1 > 4 Using IH, we can assume f i > α i for 3 i k First, rewrite α k 1 as α α k 3 α is equal to 1 + α because: α = ( 1 + ) 5 5 + 3 = = α + 1 Thus, α k 1 = (α + 1)(α k 3 ) = α k α k 3 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 5/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 6/34 Example, cont. Recursively Defined Sets and Structures α k 1 = α k α k 3 By recursive definition, we know f = f k + f k 1 Furthermore, by inductive hypothesis: f k > α k f k 1 > α k 3 Therefore, f > α k α k 3 = α k 1 We saw how to define functions and sequences recursively We can also define sets and other data structures recursively Example: Consider the set S defined as: 3 S If x S and y S, then x + y S What is the set S defined as above? Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 7/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 8/34 More Examples Strings and Alphabets Give a recursive definition of the set E of all even integers: Recursive definitions play important role in study of strings Strings are defined over an alphabet Σ Example: Σ 1 = {a, b} Give a recursive definition of N, the set of all natural numbers: Example: Σ = {0} Examples of strings over Σ 1 : a, b, aa, ab, ba, bb,... Set of all strings formed from Σ forms language called Σ Σ = {ɛ, 0, 00, 000,...} Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 9/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 30/34 5

Recursive Definition of Strings Recursive Definitions of String Operations The language Σ has natural recursive definition: ɛ Σ (empty string) If w Σ and x Σ, then wx Σ Many operations on strings can be defined recursively. Consider function l(w) which yields length of string w Since ɛ is the empty string, ɛs = s Example: Give recursive definition of l(w) Consider the alphabet Σ = {0, 1} How is the string 1 formed according to this definition? How is 10 formed? Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 31/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 3/34 Another Example Palindromes The reverse of a string s is s written backwards. Example: Reverse of abc is bca Give a recursive definition of the reverse(s) operation A palindrome is a string that reads the same forwards and backwards Examples: mom, dad, abba, Madam I m Adam,... Give a recursive definition of the set P of all palindromes over the alphabet Σ = {a, b} Base cases: Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 33/34 Işıl Dillig, CS43: Discrete Structures Strong Induction and Recursively Defined Structures 34/34 6