Induction & Recursion Weiss: ch 7.1. Recursion –a programming strategy for solving large problems –Think “divide and conquer” –Solve large problem by.

Slides:



Advertisements
Similar presentations
Mathematical Induction II Lecture 14: Nov
Advertisements

Induction Lecture 5: Sep 21 (chapter of the book and chapter of the notes)
1 Mathematical Induction. 2 Mathematical Induction: Example  Show that any postage of ≥ 8¢ can be obtained using 3¢ and 5¢ stamps.  First check for.
Induction and recursion
1.  The set N = {1,2,3,4,……..} is known as natural numbers or the set of positive integers  The natural numbers are used mainly for :  counting  ordering.
1 Intro to Induction Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
1 Mathematical Induction. 2 Mathematical Induction: Example  Show that any postage of ≥ 8¢ can be obtained using 3¢ and 5¢ stamps.  First check for.
Discrete Structures Chapter 5: Sequences, Mathematical Induction, and Recursion 5.2 Mathematical Induction I [Mathematical induction is] the standard proof.
Copyright © Cengage Learning. All rights reserved.
1 Section 3.3 Mathematical Induction. 2 Technique used extensively to prove results about large variety of discrete objects Can only be used to prove.
Mathematical Induction Readings on induction. (a) Weiss, Sec. 7.2, page 233 (b) Course slides for lecture and notes recitation. Every criticism from a.
1 Advanced Induction Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
1 Mathematical Induction. 2 Mathematical Induction: Example  Show that any postage of ≥ 8¢ can be obtained using 3¢ and 5¢ stamps.  First check for.
Induction (chapter of the book and chapter of the notes)
Methods of Proof & Proof Strategies
College Algebra Sixth Edition James Stewart Lothar Redlin Saleem Watson.
Induction and recursion
Chapter 6 Mathematical Induction
Introduction to Proofs
Mathematical Induction. F(1) = 1; F(n+1) = F(n) + (2n+1) for n≥ F(n) n F(n) =n 2 for all n ≥ 1 Prove it!
College Algebra Fifth Edition James Stewart Lothar Redlin Saleem Watson.
1 Introduction to Abstract Mathematics Chapter 4: Sequences and Mathematical Induction Instructor: Hayk Melikya 4.1- Sequences. 4.2,
Chapter 7 Recursion 1CSCI 3333 Data Structures. 2 Recurrent Sequence A recursively defined sequence – First, certain initial values are specified  c.f.,
Section 2.6 Representation of numbers. Decimal representation (base 10) Given a positive integer X, the decimal representation of X is a string of digits.
Discrete Maths: Induction/1 1 Discrete Maths Objective – –to introduce mathematical induction through examples , Semester
Mathematical Induction I Lecture 4: Sep 16. This Lecture Last time we have discussed different proof techniques. This time we will focus on probably the.
INDUCTION Lecture 23 CS2110 – Spring 2015 A scientist gave a lecture on astronomy. He described how the earth orbits the sun, which, in turn, orbits the.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
Section 3.3: Mathematical Induction Mathematical induction is a proof technique that can be used to prove theorems of the form:  n  Z +,P(n) We have.
CompSci 102 Discrete Math for Computer Science March 1, 2012 Prof. Rodger Slides modified from Rosen.
CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)
Foundations of Discrete Mathematics Chapters 5 By Dr. Dalia M. Gil, Ph.D.
1 INFO 2950 Prof. Carla Gomes Module Induction Rosen, Chapter 4.
Mathematical Induction Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If.
CSE373: Data Structures and Algorithms Lecture 2: Proof by Induction Linda Shapiro Winter 2015.
INDUCTION Slides of Ken Birman, Cornell University.
Mathematical Induction
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
INDUCTION Lecture 21 CS2110 – Spring 2014 A well-known scientist (Bertrand Russell?) once gave a public lecture on astronomy. He described how the earth.
Chapter 5. Section 5.1 Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If we can reach.
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Mathematical Induction I Lecture 5: Sep 20 (chapter of the textbook and chapter of the course notes)
INDUCTION Lecture 22 CS2110 – Fall 2009 A well-known scientist (some say it was Bertrand Russell) once gave a public lecture on astronomy. He described.
1 Discrete Mathematical Mathematical Induction ( الاستقراء الرياضي )
Mathematical Induction
Mathematical Induction EECS 203: Discrete Mathematics Lecture 11 Spring
Mathematical Induction I Lecture 19 Section 4.2 Mon, Feb 14, 2005.
3.3 Mathematical Induction 1 Follow me for a walk through...
Chapter 5 1. Chapter Summary  Mathematical Induction  Strong Induction  Recursive Definitions  Structural Induction  Recursive Algorithms.
Induction (chapter of the book and chapter of the notes)
The Foundations: Logic and Proofs
CSE 311 Foundations of Computing I
CS2210:0001Discrete Structures Induction and Recursion
Mathematical Induction II
CSE 311 Foundations of Computing I
Induction and recursion
CSE 311: Foundations of Computing
Methods of Proof A mathematical theorem is usually of the form pq
Chapter 5 Induction and Recursion
Proofs, Recursion and Analysis of Algorithms
CSE373: Data Structures and Algorithms Lecture 2: Proof by Induction
The Foundations: Logic and Proofs
Induction and recursion
CSE 311: Foundations of Computing
Exercise Use mathematical induction to prove the following formula.
Induction Chapter
Advanced Analysis of Algorithms
Mathematical Induction
Induction Rosen 5 Lecture 8: Oct 29, 30.
Induction Lecture 20 CS2110 – Spring 2013
Presentation transcript:

Induction & Recursion Weiss: ch 7.1

Recursion –a programming strategy for solving large problems –Think “divide and conquer” –Solve large problem by splitting into smaller problems of same kind Induction –A mathematical strategy for proving statements about large sets of things First we learn induction…

Functions Example: Let S:int → int be a function such that S(n) is the sum of natural numbers from 0 to n. –Iterative form: S(n) = 0+1+…+n –Closed form: S(n) = n(n+1)/2 Can we prove equality? –Theorem: For any value of n in N, S(n) = n(n+1)/2

Proving Theorem for all N : Clever Tricks

A Second Example: Sum of Squares Example: Let Q:int → int be (iterative form) Q(n) = … + n 2 Closed Form? Intuition: sum of integers  quadratic (n 2 + n)/2 Guess: sum of squares  cubic (an 3 + bn 2 + cn + d) Coefficients: a = 1/3, b = ½, c = 1/6, d = 0 Q CF (n) = n 3 /3 + n 2 /2 + n/6 = n(n+1)(2n+1)/6 Conjecture: P(n): Q(n) = Q CF (n) But how to prove P(n) for all n?

Recursive Form Rewrite Q as: Q(n) = … + (n-1) 2 + n 2 = Q(n-1) + n 2 Each term defined as a function of the one before it recursive case: Q RF (n) = Q RF (n-1) + n 2 We still need a ‘first’ term base case: Q RF (1) = 1 2 = 1

Evaluating a Recursive Definition Q(5) = Q(4) = = 55 Q(4) = Q(3) = = 30 Q(3) = Q(2) = = 14 Q(2) = Q(1) = = 5 Q(1) = 1 (base case)

Induction: A Bizzare Example 1 Consider a planet X, where the following rule holds: “If it rains one day, it also rains the next day” Consider two scenarios. 1 Adapted from

Scenario A You land on planet X and it does not rain on the day you arrive. What can you conclude? a)It will never rain on planet X. b)It has never rained on planet X. c)It did not rain yesterday on planet X. d)It will rain tomorrow on planet X.

Scenario B You land on planet X and it does rain on the day you arrive. What can you conclude? e)It rains every day on planet X. f)It will rain tomorrow on planet X. g)It rained yesterday on planet X. h)It will rain every day from now on.

Induction Mathematical argument consisting of: –A base case: A particular statement, say P(1), that is true. –An inductive hypothesis: Assume we know P(n) is true. –An inductive step: If we know P(n) is true, we can infer that P(n+1) is true.

Proof of C(n): Q(n) = Q CF (n) Base case: Q(1) = 1 = 1(1+1)(2*1+1)/6 = Q CF (1) so P(1) holds. Inductive hypothesis: Let us assume P(n). That is, Q(n) = Q CF (n) = (n+1)(2n+1)/6 Inductive step: Q(n+1) = Q(n) + (n+1) 2 from recursive form = n(n+1)(2n+1)/6 + (n+1) 2 from i.h. = (n+1)(n+2)(2n+3)/6 from algebra = Q CF (n) Thus P(n+1) holds. Conclusion: Q(n) = Q CF (n) for all n >= 1

Say What? Proof by induction that P(n) for all n: –P(1) holds, because …. –Let’s assume P(n) holds. –P(n+1) holds, because … –Thus, by induction, P(n) holds for all n. Your job: –Choose a good property P(n) to prove. hint: deciding what n is may be tricky –Copy down the proof template above. –Fill in the two ‘…’ –Relax.

Sum of Integers (redux) Conjecture P(n): The sum S(n) of the first n integers is equal to n(n+1)/2. Recursive Form: Proof by induction:

More Examples Prove for all n  1, that 133 divides 11 n n-1. P(n) = No recursive form here… Proof by induction…

More Examples Prove that n! > 2 n for all integers n  4. P(n) = No recursive form here… Proof by induction…

Induction (Variation 1) We don’t have to start with P(1) only. –Often start with P(0), and prove for all n >= 0 –Can start with P(n 0 ), and prove for all n >= n 0 (does not say anything about 0, 1, …, n 0 -1 though!) –Can start with several base cases, P(0), P(1),.., P(k), then use induction for n >= k.

Tiling Problem Problem: –Chess board with one square missing –Can we fill remainder with “L” shaped tiles? Sanity check: 64 squares remaining, divisible by 3 8 8

Use Induction What is n? –Number of squares missing? –Number of tiles already placed? –Number of squares remaining? Consider a 2 n by 2 n board

Base case

4x4 case

General Case

Induction Gone Awry Definition: If a != b are two positive integers, define max(a, b) as the larger of a or b. If a = b define max(a, b) = a = b. Conjecture A(n): if a and b are two positive integers such that max(a, b) = n, then a = b. Proof (by induction): Base Case: A(1) is true, since if max(a, b) = 1, then both a and b are at most 1. Only a = b = 1 satisfies this condition. Inductive Case: Assume A(n) for n >= 1, and show that A(n+1). If max(a, b) = n+1, then max(a-1, b-1) = n. By the inductive hypothesis, a-1 = b-1, so a = b. Corrollary: 3 = 5 Proof: max(3, 5) = 5. Since A(5) is true, then 3 = 5.

Caveats When proving something by induction… –Often easier to prove a more general (harder) problem –Extra conditions makes things easier in inductive case You have to prove more things in base case & inductive case But you get to use the results in your inductive hypothesis e.g., tiling for n x n boards is impossible, but 2 n x 2 n works –You must verify conditions before using I. H. Induction often fails –Doesn’t mean the property is false –Choosing what to prove is usually the hardest part Exercises (optional) on web site & in Weiss

Strong Induction (Variation 2) Up till now, we used weak induction Proof by (strong) induction that P(n) for all n: –P(1) holds, because …. –Let’s assume P(m) holds for 1 <= m <= n. (that is, P(1) holds, P(2) holds, …, and P(n) holds). –P(n+1) holds, because … –Thus, by induction, P(n) holds for all n.

Postage Stamps Prove that every amount of postage of 12¢ or more can be formed using 4¢ and 5¢ stamps. –What is P(n)? –What base case(s)?