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

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

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

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

Induction and recursion. Chapter 5

Exercises. Template for Proofs by Mathematical Induction

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

CSE 311: Foundations of Computing. Lecture 14: Induction

Mathematical Induction

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

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

Mathematical Induction. Section 5.1

Discrete Mathematics. Spring 2017

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

Induction and Recursion

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

Proof by Induction. Andreas Klappenecker

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

Mathematical Induction. EECS 203: Discrete Mathematics Lecture 11 Spring

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

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 1

Discrete Mathematics and Probability Theory Spring 2014 Anant Sahai Note 3

With Question/Answer Animations

PRINCIPLE OF MATHEMATICAL INDUCTION

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

MAC-CPTM Situations Project

Climbing an Infinite Ladder

CSC236H Lecture 2. Ilir Dema. September 19, 2018

Mathematical Induction

Climbing an Infinite Ladder

MAT 300 RECITATIONS WEEK 7 SOLUTIONS. Exercise #1. Use induction to prove that for every natural number n 4, n! > 2 n. 4! = 24 > 16 = 2 4 = 2 n

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

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

Induction. Induction. Induction. Induction. Induction. Induction 2/22/2018

MATH 55 - HOMEWORK 6 SOLUTIONS. 1. Section = 1 = (n + 1) 3 = 2. + (n + 1) 3. + (n + 1) 3 = n2 (n + 1) 2.

Review 3. Andreas Klappenecker

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

CSC 344 Algorithms and Complexity. Proof by Mathematical Induction

Logic, Sets, and Proofs

EECS 1028 M: Discrete Mathematics for Engineers

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

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

Discrete Mathematics. Spring 2017

Discrete Mathematics for CS Spring 2008 David Wagner Note 4

Lecture 6 : Induction DRAFT

Mathematical Fundamentals

Lecture 3.2: Induction, and Strong Induction

Chapter 2. Mathematical Reasoning. 2.1 Mathematical Models

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

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

Introduction to Induction (LAMC, 10/14/07)

1 Recursive Algorithms

Binomial Coefficient Identities/Complements

CHAPTER 5 Induction and Recursion

Prompt. Commentary. Mathematical Foci

What can you prove by induction?

n n P} is a bounded subset Proof. Let A be a nonempty subset of Z, bounded above. Define the set

Assignment 3 Logic and Reasoning KEY

Mathematical Structures Combinations and Permutations

Induction and recursion. Topics. Induction and Recursion Vojislav Kecman CMSC 302

INDUCTION AND RECURSION. Lecture 7 - Ch. 4

CSCE 222 Discrete Structures for Computing. Review for the Final. Hyunyoung Lee

At least one of us is a knave. What are A and B?

Hence, the sequence of triangular numbers is given by., the. n th square number, is the sum of the first. S n

CSC236 Week 2. Larry Zhang

Review 1. Andreas Klappenecker

PUTNAM TRAINING MATHEMATICAL INDUCTION. Exercises

Reading and Writing. Mathematical Proofs. Slides by Arthur van Goetham

Reading 5 : Induction

Section 4.2: Mathematical Induction 1

Proof Techniques (Review of Math 271)

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.

COM S 330 Lecture Notes Week of Feb 9 13

Quiz 1, Mon CS 2050, Intro Discrete Math for Computer Science

Math 324 Summer 2012 Elementary Number Theory Notes on Mathematical Induction

CS173 Lecture B, September 10, 2015

CS173 Strong Induction and Functions. Tandy Warnow

n f(k) k=1 means to evaluate the function f(k) at k = 1, 2,..., n and add up the results. In other words: n f(k) = f(1) + f(2) f(n). 1 = 2n 2.

Finite Automata Theory and Formal Languages TMV027/DIT321 LP Recap: Logic, Sets, Relations, Functions

STUDY PROBLEMS FOR EXAM I CMSC 203 DISCRETE STRUCTURES. n (n +1)(2n +1), 6. j 2 = 1(1+1)(2 1+1) 6. k (k +1)(2k +1) 6

Section 7.1 Relations and Their Properties. Definition: A binary relation R from a set A to a set B is a subset R A B.

TECHNISCHE UNIVERSITEIT EINDHOVEN Faculteit Wiskunde en Informatica. Final exam Logic & Set Theory (2IT61) (correction model)

Predicate Logic. Andreas Klappenecker

12 Sequences and Recurrences

Discrete Mathematics & Mathematical Reasoning Induction

Math Circle: Recursion and Induction

Module 9: Mathematical Induction

CSE20: Discrete Mathematics

Department of Computer Science University at Albany, State University of New York Solutions to Sample Discrete Mathematics Examination II (Fall 2007)

Chapter 3: Propositional Calculus: Deductive Systems. September 19, 2008

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

SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION

Lecture 2: Proof Techniques Lecturer: Lale Özkahya

CSE 20 DISCRETE MATH WINTER

CSE 20 DISCRETE MATH SPRING

Mathematical Induction Assignments

Lecture Overview. 2 Weak Induction

Math 230 Final Exam, Spring 2008

1.2 The Well-Ordering Principle

Mathematical Reasoning Rules of Inference & Mathematical Induction. 1. Assign propositional variables to the component propositional argument.

CSE 20 DISCRETE MATH. Fall

Transcription:

How does discrete math help us Helps create a solution (program) Helps analyze a program How does discrete math help (CS160)? Helps create a solution (program) q Logic helps you understand conditionals q Logic, functions, tuples, sets help with classes/ objects/methods, and later with databases (relational algebra and relational calculus) q Loop invariants help you create iterative solutions Helps analyze a program q Prove program correctness (e.g., using loop invariants) How does discrete math help (CS161)? Helps create a solution (program) q Induction helps you create recursive solutions Builds on logic, algebra, logical thinking, proof techniques from CS160 Mathematical Induction Helps analyze a program q Prove program correctness Induction q Performance (actually computational complexity time and space) Counting, permutations and combinations Rosen Chapter 5 1

Motivation Many mathematical statements have the form: n N, P(n) P(n): Logical predicate : For every positive value of n, 1 + 2 +,, + n = n(n + 1)/2. Predicate propositional function that depends on a variable, and has a truth value once the variable is assigned a value. Mathematical induction is a proof technique for proving such statements Mathematical Induction and the Domino Principle If the 1 st domino falls over and the nth domino falls over implies that domino (n + 1) falls over then domino n falls over for all n N. image from http://en.wikipedia.org/wiki/file:dominoeffect.png A Geometrical interpretation 1: 2: 3: Put these blocks, which represent numbers, together to form sums: 1 + 2 = 1 + 2 + 3 = A Geometrical interpretation n n Area is n 2 /2 + n/2 = n(n + 1)/2 2

Proving P(3) Suppose we know: P(1) (P(n) P(n + 1)) n 1. Prove: P(3) Proof: 1. P(1). [premise] 2. P(1) P(2). [specialization of premise] 3. P(2). [step 1, 2, & modus ponens] 4. P(2) P(3). [specialization of premise] 5. P(3). [step 3, 4, & modus ponens] We can construct a proof for every finite value of n Modus ponens: if p and p q then q : 1 + 2 + + n = n(n + 1)/2. Let F(n) = 1 + 2 + + n P(n): F(n) = n(n + 1) / 2 Verify: P(1): 1(1 + 1)/2 = 1. Assume P(n), i.e. F(n) = n(n + 1)/2 Show P(n+1): F(n + 1) = (n + 1)(n + 2)/2. F(n + 1) = 1 + 2 +... + n + (n + 1) = F(n) + n + 1 = n(n + 1)/2 + n + 1 [Induction hyp.] = n(n + 1)/2 + 2(n + 1)/2 = (n + 1)(n + 2)/2. The Principle of Mathematical Induction Let P(n) be a statement that, for each natural number n, is either true or false. To prove that n N, P(n), it suffices to prove: q P(1) is true. (base case) q n N, P(n) P(n + 1). (inductive step) This is not magic. It is a recipe for constructing a proof for an arbitrary n N. Proof by induction 3 steps: q Prove P(1). [the basis] q Assume P(n) [the induction hypothesis] q Using P(n) prove P(n + 1) [the inductive step] 3

Ø Show that any postage of 8 can be obtained using 3 and 5 stamps. Ø First check for a few values: 8 = 3 + 5 9 = 3 + 3 + 3 10 = 5 + 5 11 = 5 + 3 + 3 12 = 3 + 3 + 3 + 3 Ø How to generalize this? Let P(n) be the statement n cents postage can be obtained using 3 and 5 stamps. Want to show that P(k) is true implies P(k+1) is true for all k 8. 2 cases: 1) P(k) is true and the k cents contain at least one 5. 2) P(k) is true and the k cents do not contain any 5. Case 1: k cents contain at least one 5 stamp. k cents Replace 5 stamp by two 3 stamps 5 3 3 k+1 cents Show that 1 + 3 + 5 +... + (2n+1) = (n+1) 2 Case 2: k cents do not contain any 5 stamp. Then there are at least three 3 stamp. k cents 3 Replace three 3 stamps by 3 two 5 stamps 3 5 5 k+1 cents 15 4

Now prove the basis step Now complete the proof Given P(k), prove P(k+1), i.e. Given 1 + 2 + 2 2 + + 2 k = 2 k + 1 1 Prove q 1 + 2 + 2 2 + + 2 k+1 = 2 k + 2 1 s Show that 1 + 3 + 5 +... + (2n+1) = (n+1) 2 Show that 1 + 2 + 2 2 + + 2 n = 2 n + 1 1 Show that for n 4 2 n < n! Show that n 3 n is divisible by 3 for every positive n. Prove that a set with n elements has 2 n subsets Strong induction Induction: q P(1) is true. q n N, P(n) P(n + 1). q Implies n N, P(n) Strong induction: q P(1) is true. q n N, (P(1) P(2) P(n)) P(n + 1). q Implies n N, P(n) 5

7/1/15 Prove that all natural numbers 2 can be represented as a product of primes. Basis: 2: 2 is a prime. Assume that 1, 2,, n can be represented as a Show that n+1 can be represented as a product of primes. q q product of primes. If n+1 is a prime: It can be represented as a product of 1 prime, itself. If n+1 is composite: Then, n + 1 = ab, for some a,b < n + 1. Breaking chocolate Theorem: Breaking up a chocolate bar with n squares takes n-1 breaks. Therefore, a = p1p2... pk & b = q1q2... ql, where the pis & qis are primes. Represent n+1 = p1p2... pkq1q2... ql. All horses have the same color Base case: If there is only one horse, there is only one color. Induction step: q q Assume as induction hypothesis that within any set of n horses, there is only one color. Now look at any set of n + 1 horses. Number them: 1, 2, 3,..., n, n + 1. Consider the sets {1, 2, 3,..., n and {2, 3, 4,..., n + 1. Each is a set of only n horses, therefore within each there is only one color. But the two sets overlap, so there must be only one color among all n + 1 horses. This is clearly wrong, but can you find the flaw? 6

7/1/15 All horses have the same color The inductive step requires that k >= 3, otherwise there is not intersection! So P(2) should be the base case, which is obviously incorrect. Induction and Recursion // Returns base ^ exponent. // Precondition: exponent >= 0 public static int pow(int x, int n) { if (n == 0) { // base case; any number to 0th power is 1 return 1; else { // recursive case: x^n = x * x^(n-1) return x * pow(x, n-1); In the book there is a similar example. Induction and Recursion public static int pow(int x, int n) { if (n == 0){ return 1; else { return x * pow(x, n-1); Claim: the algorithm correctly computes xn. Proof: By induction on n Base case: n = 0: it correctly returns 1 Inductive step: assume that for n the algorithm correctly returns xn. Then for n+1 it returns x xn = xn+1. Induction is useful for proving correctness/ design of recursive algorithms Induction and Recursion n! of some integer n can be characterized as: n! = 1 for n = 0; otherwise n! = n (n - 1) (n - 2)... 1 Want to write a recursive method for computing it. We notice that n! = n (n 1)! This is all we need to put together the method: public static int factorial(int n) { if (n == 0) { return 1; else { return n * factorial(n-1); 7

Hanoi Induction in CS from via to Recall the recursive solution public void hanoi(int n, int from, int to, int via) { if (n>0) { hanoi(n-1,from, via, to); System.out.println("move disk " + n + " from " + from + " to " + to); hanoi(n-1,via, to, from); Induction is a powerful tool for showing algorithm correctness not just for recursive algorithms (CS320) If you assume the inductive hypothesis that you can move k=n-1 disks, then adding one more disk is easy. For the k+1 case (where k+1 = n), move the top k disks, move the bottom disk, and move the top k disks. More induction examples Let n be a positive integer. Show that every 2 n x 2 n chessboard with one square removed can be tiled using right triominoes, each covering three squares at a time. Celebrity problem A celebrity is a guest at a party who is known to every other guest, but knows none of them At most one celebrity at a party. To find out who is a celebrity, you can ask any guest G i a question of the form Do you know G j? Prove that you need at most 3(n-1) questions. P(1) is vacuously true! You don t need to ask. If you did ask, it can become a philosophical question! Do you know yourself? 8