Induction. Announcements. Overview. Defining Functions. Sum of Squares. Closed-form expression for SQ(n) There have been some corrections to A1

Similar documents
Sum of Squares. Defining Functions. Closed-Form Expression for SQ(n)

Mathematical Induction. Defining Functions. Overview. Notation for recursive functions. Base case Sn(0) = 0 S(n) = S(n 1) + n for n > 0

CS 220: Discrete Structures and their Applications. Mathematical Induction in zybooks

Mathematical Induction Assignments

Discrete Mathematics. Spring 2017

Mathematical Induction

Discrete Mathematics for CS Spring 2008 David Wagner Note 4

CSC 344 Algorithms and Complexity. Proof by Mathematical Induction

At the start of the term, we saw the following formula for computing the sum of the first n integers:

Discrete Mathematics. Spring 2017

Proof by Induction. Andreas Klappenecker

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 1

CS 2110: INDUCTION DISCUSSION TOPICS

Mathematical Induction. Section 5.1

COM S 330 Lecture Notes Week of Feb 9 13

AQA Level 2 Further mathematics Further algebra. Section 4: Proof and sequences

Discrete Mathematics and Probability Theory Spring 2014 Anant Sahai Note 3

CSCE 222 Discrete Structures for Computing. Proof by Induction. Dr. Hyunyoung Lee. !!!!!! Based on slides by Andreas Klappenecker

Math Circle: Recursion and Induction

Lecture 6 : Induction DRAFT

Mathematical Induction

21 Induction. Tom Lewis. Fall Term Tom Lewis () 21 Induction Fall Term / 14

Mathematical Induction

Mathematical Induction. Rosen Chapter 4.1,4.2 (6 th edition) Rosen Ch. 5.1, 5.2 (7 th edition)

Mathematical Induction. How does discrete math help us. How does discrete math help (CS160)? How does discrete math help (CS161)?

Induction and Recursion

Chapter Summary. Mathematical Induction Strong Induction Well-Ordering Recursive Definitions Structural Induction Recursive Algorithms

Use mathematical induction in Exercises 3 17 to prove summation formulae. Be sure to identify where you use the inductive hypothesis.

Discrete Mathematics for CS Fall 2003 Wagner Lecture 3. Strong induction

Every subset of {1, 2,...,n 1} can be extended to a subset of {1, 2, 3,...,n} by either adding or not adding the element n.

Chapter 2. Mathematical Reasoning. 2.1 Mathematical Models

Climbing an Infinite Ladder

PROOF WITHOUT WORDS MATH CIRCLE (BEGINNERS) 05/06/2012

Consider an infinite row of dominoes, labeled by 1, 2, 3,, where each domino is standing up. What should one do to knock over all dominoes?

n(n + 1). 2 . If n = 3, then 1+2+3=6= 3(3+1) . If n = 2, then = 3 = 2(2+1)

12 Sequences and Recurrences

Induction and recursion. Chapter 5

Prompt. Commentary. Mathematical Foci

9.4. Mathematical Induction. Introduction. What you should learn. Why you should learn it

Exercises. Template for Proofs by Mathematical Induction

Reading 5 : Induction

EECS 1028 M: Discrete Mathematics for Engineers

Induction 1 = 1(1+1) = 2(2+1) = 3(3+1) 2

Problem Set 5 Solutions

What can you prove by induction?

3.1 Induction: An informal introduction

CISC-102 Fall 2017 Week 3. Principle of Mathematical Induction

With Question/Answer Animations

Another Proof By Contradiction: 2 is Irrational

3 - Induction and Recursion

Announcements. Read Section 2.1 (Sets), 2.2 (Set Operations) and 5.1 (Mathematical Induction) Existence Proofs. Non-constructive

Proof by Mathematical Induction.

CSI Mathematical Induction. Many statements assert that a property of the form P(n) is true for all integers n.

CSE 311: Foundations of Computing. Lecture 14: Induction

CSE373: Data Structures and Algorithms Lecture 2: Proof by Induction. Linda Shapiro Spring 2016

1 Implication and induction

Lecture 4: Probability, Proof Techniques, Method of Induction Lecturer: Lale Özkahya

SYDE 112, LECTURE 7: Integration by Parts

MATH 301 INTRO TO ANALYSIS FALL 2016

THE ISLAMIC UNIVERSITY OF GAZA ENGINEERING FACULTY DEPARTMENT OF COMPUTER ENGINEERING DISCRETE MATHMATICS DISCUSSION ECOM Eng. Huda M.

4.1 Induction: An informal introduction

MAC-CPTM Situations Project

Proving languages to be nonregular

Mat Week 8. Week 8. gcd() Mat Bases. Integers & Computers. Linear Combos. Week 8. Induction Proofs. Fall 2013

Appendix G: Mathematical Induction

INDUCTION AND RECURSION. Lecture 7 - Ch. 4

CS1800: Mathematical Induction. Professor Kevin Gold

Student Responsibilities Week 8. Mat Section 3.6 Integers and Algorithms. Algorithm to Find gcd()

MATHEMATICAL INDUCTION

CS173 Lecture B, September 10, 2015

Chapter 11 - Sequences and Series

CSC236 Week 2. Larry Zhang

Mathematical Induction

Discrete Mathematics and Probability Theory Spring 2016 Rao and Walrand Note 3

Problem Solving in Math (Math 43900) Fall 2013

CMPSCI 250: Introduction to Computation. Lecture 11: Proof Techniques David Mix Barrington 5 March 2013

Sequences & Mathematical Induction

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2

CSE373: Data Structures and Algorithms Lecture 2: Math Review; Algorithm Analysis. Hunter Zahn Summer 2016

Proof. Theorems. Theorems. Example. Example. Example. Part 4. The Big Bang Theory

COS 341 Discrete Mathematics

Geometric Series and the Ratio and Root Test

Announcements. CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis. Today. Mathematical induction. Dan Grossman Spring 2010

Mathematical Induction. EECS 203: Discrete Mathematics Lecture 11 Spring

Olympiad Constructions Cody Johnson. Constructions. July 14, 2016 Cody Johnson.

Section 4.2: Mathematical Induction 1

MODEL ANSWERS TO THE THIRD HOMEWORK. 1. We prove this result by mathematical induction. Let P (n) be the statement that

CHAPTER 4 SOME METHODS OF PROOF

Conjectures and proof. Book page 24-30

Mathematical Induction

Mathematical Induction Again

Summer HSSP Lecture Notes Week 1. Lane Gunderman, Victor Lopez, James Rowan

Lecture 3: Sizes of Infinity

Mathematical Induction Again

Section 3.1 Quadratic Functions

Math 291-1: Lecture Notes Northwestern University, Fall 2015

Lecture 2: Proof Techniques Lecturer: Lale Özkahya

Mathematical induction. Limits of sequences

Sums and Products. a i = a 1. i=1. a i = a i a n. n 1

What is proof? Lesson 1

Transcription:

Induction There have been some corrections to A1 Check the website and the newsgroup Announcements Upcoming topic: Recursion Lecture 3 CS 211 Fall 2005 Overview Recursion a programming strategy that solves a problem by reducing it to simpler or smaller instance(s) of the same problem Induction a mathematical strategy for proving statements about natural numbers 0,1,2,... (or more generally, about inductively defined objects) Induction and recursion are very closely related Defining Functions It is often useful to write a given function in different ways Let S : int int be the function where S(n) is the sum of the integers from 0 to n. E.g., S(0) = 0 S(3) = 0+1+2+3 = 6 Definition: iterative form S(n) = 0+1+ + n Another characterization: closed form S(n) = n(n+1)/2 Sum of Squares Here is a more complex example. Let SQ : int int be the function that gives the sum of the squares of integers from 0 to n. E.g., SQ(0) = 0 SQ(3) = 0 2 + 1 2 + 2 2 + 3 2 = 14 Definition: SQ(n) = 0 2 + 1 2 + + n 2 Is there an equivalent closed-form expression? Closed-form expression for SQ(n) Sum of integers between 0 through n was n(n+1)/2 which is a quadratic in n. Inspired guess: perhaps sum of squares of integers between 0 through n is a cubic in n. So conjecture: SQ(n) = an 3 +bn 2 +cn+d where a,b,c,d are unknown coefficients. How can we find the values of the four unknowns? Use any 4 values of n to generate 4 linear equations, and solve

Finding coefficients SQ(n) = 0 2 +1 2 + +n 2 = an 3 +bn 2 +cn+d This suggests SQ(n) = 0 2 + 1 2 + + n 2 Use n=0,1,2,3 SQ(0) = 0 = a 0 + b 0 + c 0 +d SQ(1) = 1 = a 1 + b 1 + c 1 + d SQ(2) = 5 = a + b 4 + c 2 + d SQ(3) = 14 = a 27 + b 9 + c 3 +d Solve these 4 equations to get a = 1/3, b = ½, c = 1/6, d = 0 = n 3 /3 + n 2 /2 + n/6 = n(n+1)(2n+1)/6 Question: How do we know this closed-form solution is true for all values of n? Remember, we only used n = 0,1,2,3 to determine these coefficients. We do not know that the closed-form expression is valid for other values of n. To solve this problem, let us express SQ(n) in another way. One approach: Try a few other values of n to see if they work. Try n = 5: SQ(n) = 0+1+4+9+16+25 = 55 Closed-form expression: 5 6 11/6 = 55 Works! Try some more values Problem: we can never prove validity of closedform solution for all values of n this way since there are an infinite number of values of n. SQ(n) = 0 2 + 1 2 + + (n 1) 2 + n 2 SQ(n 1) This leads to the following recursive definition of SQ: SQ(0) = 0 SQ(n) = SQ(n 1) + n 2, n > 0 To get a feel for this definition, let us look at SQ(4) = SQ(3) + 4 2 = SQ(2) + 3 2 + 4 2 = SQ(1) + 2 2 + 3 2 + 4 2 = SQ(0) + 1 2 + 2 2 + 3 2 + 4 2 = 0 + 1 2 + 2 2 + 3 2 + 4 2 Notation for recursive functions Can we show that these two functions are equal? Base case SQ(0) = 0 SQ(n) = SQ(n 1) + n 2, n > 0 SQ r (0) = 0 SQ r (n) = SQ r (n-1) + n 2, n > 0 SQ c (n) = n(n+1)(2n+1)/6 (r=recursive) (c=closed-form) Recursive case

Dominoes 0 1 2 3 4 5 Assume equally spaced dominoes, and assume that spacing between dominoes is less than domino length. How would you argue that all dominoes would fall? Dumb argument: Domino 0 falls because we push it over. Domino 0 hits domino 1, therefore domino 1 falls. Domino 1 hits domino 2, therefore domino 2 falls. Domino 2 hits domino 3, therefore domino 3 falls.... Is there a more compact argument we can make? Better argument Argument: Domino 0 falls because we push it over (base case). Assume that domino k falls over (inductive hypothesis). Because domino k s length is larger than inter-domino spacing, it will knock over domino k+1 (inductive step). Because we could have picked any domino to be the k th one, we conclude that all dominoes will fall over (conclusion). This is an inductive argument. This is called weak induction. There is also strong induction (later). Not only is it more compact, but it works for an infinite number of dominoes! Weak induction over integers We want to prove that some property P(n) holds for all integers n > 0. Inductive argument: Base case P(0): Show that property P is true for 0. Inductive step: P(k) implies P(k+1): Assume that P(k) is true for an unspecified integer k (this is the inductive hypothesis). Under this assumption, show that P(k+1) is true. Because we could have picked any k, we can conclude that P(n) holds for all integers n > 0. SQ r (n) = SQ c (n) for all n? Define P(n) as SQ r (n)= SQ c (n) P(0) P(1) P(2) P(k) P(k+1) Prove P(0). Assume P(k) for unspecified k, and prove P(k+1) under this assumption. SQ r (0) = 0 SQ c (n) = n(n+1)(2n+1)/6 SQ r (n) = SQ r (n-1) + n 2, n > 0 Let P(n) be the proposition that SQ r (n) = SQ c (n). Proof by induction: P(0): SQ r (0) = 0 = SQ c (0) P(k) => P(k+1): Assume SQ r (k) = SQ c (k), prove that SQ r (k+1) = SQ c (k+1) SQ r (k+1) = SQ r (k) + (k+1) 2 (definition of SQ r ) = SQ c (k) + (k+1) 2 (inductive hypothesis) = k(k+1)(2k+1)/6 + (k+1) 2 (definition of SQ c ) = (k+1)(k+2)(2k+3)/6 (algebra) = SQ c (k+1) (definition of SQ c ) Therefore SQ r (n) = SQ c (n) for all n. Another example Prove that 0+1+...+n = n(n+1)/2 Basis n=0: 0 = 0 Inductive step: Assume 1+2+...+k = k(k+1)/2 for an unspecified k. This is the inductive hypothesis. Under this assumption, show that 1+2+...+(k+1) = (k+1)(k+2)/2. 0 + 1 + + k + (k+1) = (0 + 1 + + k) + (k+1) = k(k+1)/2 + (k+1) = (k+1)(k+2)/2 Therefore, if result is true for k, it is true for k+1. Conclusion: the result holds for all n.

0 1 Note on base case 2 3 4 5 Sometimes we are interested in showing some proposition is true for integers b Intuition: we knock over domino b, and dominoes in front get knocked over. Not interested in 0,1,,(b 1) In general, base case in induction does not have to be 0. If base case is some integer b, induction proves the proposition for n = b, b+1, b+2, Does not say anything about n = 0,1,,b 1 Weak induction: nonzero base case Example: You can make any amount of postage above with some combination of 3 and 5 stamps. Basis: true for : = 3 + 5 Induction step: suppose true for k. If used a 5 stamp to make k, replace it by two 3 stamps. Get k+1. If did not use a 5 stamp to make k, must have used at least three 3 stamps. Replace three 3 stamps by two 5 stamps. Get k+1. More on induction In some problems, it may be tricky to determine how to set up the induction: What are the dominoes? This is particularly true in geometric problems that can be attacked using induction. A Tiling Problem A chessboard has one square cut out of it. Can the remaining board be tiled using tiles of the shape shown in the picture (rotation allowed)? Not obvious that we can use induction! Idea Consider boards of size 2 n x 2 n for n = 1,2, Basis: show that tiling is possible for 2 x 2 board. Inductive step: assuming 2 k x 2 k board can be tiled, show that 2 k+1 x 2 k+1 board can be tiled. Conclude that any 2 n x 2 n board can be tiled, n = 1,2, Chessboard ( x ) is a special case of this argument. We have proved the x special case by solving a more general problem! 2 x 2 board Basis The 2 x 2 board can be tiled regardless of which one of the four pieces has been omitted

4 x 4 case 2 n+1 x 2 n+1 case Divide the 4 x 4 board into four 2 x 2 sub-boards. One of the four sub-boards has the missing piece. By the induction hypothesis, that sub-board can be tiled since it is a 2 x 2 board with a missing piece. Tile the center squares of the three remaining sub-boards as shown. This leaves 3 2 x 2 boards with a missing piece, which can be tiled by the induction hypothesis. Divide board into four sub-boards and tile the center squares of the three complete sub-boards. The remaining portions of the sub-boards can be tiled by the assumption about 2 n x 2 n boards. When induction fails Sometimes an inductive proof strategy for some proposition may fail. This does not necessarily mean that the proposition is wrong. It may just mean that the inductive strategy you are trying fails. A different induction hypothesis (or a different proof strategy altogether) may succeed. Tiling example (cont.) Let us try a different inductive strategy which will fail. Proposition: any n x n board with one missing square can be tiled. Problem: a 3 x 3 board with one missing square has remaining squares, but our tile has 3 squares. Tiling is impossible. Therefore, any attempt to give an inductive proof of this proposition must fail. This does not say anything about the x case. A Seemingly Similar Tiling Problem A chessboard has opposite corners cut out of it. Can the remaining board be tiled using tiles of the shape shown in the picture (rotation allowed)? Induction fails here. Why? (Well for one thing, this board can t be tiled with dominos.) Strong induction We want to prove that some property P holds for all n. Weak induction: P(0): show that property P is true for 0 P(k) => P(k+1): show that if property P is true for k, it is true for k+1 Conclude that P(n) holds for all n. Strong induction: P(0): show that property P is true for 0 P(0) and P(1) and and P(k) => P(k+1): show that if P is true for numbers less than or equal to k, it is true for k+1 Conclude that P(n) holds for all n. Both proof techniques are equally powerful.

Conclusion Induction is a powerful proof technique Recursion is a powerful programming technique Induction and recursion are closely related. We can use induction to prove correctness and complexity results about recursive programs. Examples next time!