Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Mathematical Induction Prudence Wong

Slides:



Advertisements
Similar presentations
Reasoning About Code; Hoare Logic, continued
Advertisements

13.4 Mathematical Induction. Mathematical Induction is a common method of proving that each statement of an infinite sequence of mathematical statements.
1 Mathematical Induction. 2 Mathematical Induction: Example  Show that any postage of ≥ 8¢ can be obtained using 3¢ and 5¢ stamps.  First check for.
Self-Reference - Induction Cmput Lecture 7 Department of Computing Science University of Alberta ©Duane Szafron 1999 Some code in this lecture is.
Discussion #131/18 Discussion #13 Induction (the process of deriving generalities from particulars) Mathematical Induction (deductive reasoning over the.
Logic: Connectives AND OR NOT P Q (P ^ Q) T F P Q (P v Q) T F P ~P T F
Proof by Induction and contradiction Leo Cheung. The TAs Our office is in SHB117, feel free to come if you get problems about the course Or ask your questions.
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 12 Number theory Mathematical induction Proof by induction Examples.
Chapter 10 Sequences, Induction, and Probability Copyright © 2014, 2010, 2007 Pearson Education, Inc Mathematical Induction.
DAST 2005 Tirgul 6 Heaps Induction. DAST 2005 Heaps A binary heap is a nearly complete binary tree stored in an array object In a max heap, the value.
Mathematical Induction Readings on induction. (a) Weiss, Sec. 7.2, page 233 (b) Course slides for lecture and notes recitation. Every criticism from a.
CSE115/ENGR160 Discrete Mathematics 03/29/11 Ming-Hsuan Yang UC Merced 1.
1 Strong Mathematical Induction. Principle of Strong Mathematical Induction Let P(n) be a predicate defined for integers n; a and b be fixed integers.
1 Mathematical Induction. 2 Mathematical Induction: Example  Show that any postage of ≥ 8¢ can be obtained using 3¢ and 5¢ stamps.  First check for.
Mathematics.
Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.
MATHEMATICS INDUCTION AND BINOM THEOREM By : IRA KURNIAWATI, S.Si, M.Pd.
MATH 224 – Discrete Mathematics
Chapter 6 Mathematical Induction
CSNB143 – Discrete Structure Topic 5 – Induction Part I.
Discrete Mathematics Tutorial 11 Chin
Discrete Maths: Induction/1 1 Discrete Maths Objective – –to introduce mathematical induction through examples , Semester
Module #13: Inductive Proofs Rosen 5 th ed., § inference of a generalized conclusion from particular instances 2. mathematical demonstration of the.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.
Foundations of Discrete Mathematics Chapters 5 By Dr. Dalia M. Gil, Ph.D.
1+2+3+…+n = n(n+1)/2 We want to prove the above statement by mathematical Induction for all natural numbers (n=1,2,3,…) Next SlideSlide 1.
Inductive Proofs and Inductive Definitions Jim Skon.
CSE373: Data Structures and Algorithms Lecture 2: Proof by Induction Linda Shapiro Winter 2015.
Mathematical Induction
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
1 2/21/2016 MATH 224 – Discrete Mathematics Sequences and Sums A sequence of the form ar 0, ar 1, ar 2, ar 3, ar 4, …, ar n, is called a geometric sequence.
Quiz 7 The way I expected it.. How to do it! 1. Let P(n) be the statement that n 2 = n(n + 1)(2n + 1)/6 for the positive integer n. Be.
Mathematical Induction I Lecture 5: Sep 20 (chapter of the textbook and chapter of the course notes)
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 a particular.
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.
INDUCTION David Kauchak CS52 – Spring to-1 multiplexer control control_negate and_out1 input0 input1 and_out2 output.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
Chapter 5 1. Chapter Summary  Mathematical Induction  Strong Induction  Recursive Definitions  Structural Induction  Recursive Algorithms.
Mathematical Induction. The Principle of Mathematical Induction Let S n be a statement involving the positive integer n. If 1.S 1 is true, and 2.the truth.
Hubert Chan (Chapters 1.6, 1.7, 4.1)
11.7 – Proof by Mathematical Induction
MATH 224 – Discrete Mathematics
CSE15 Discrete Mathematics 03/22/17
COMP108 Algorithmic Foundations Mathematical Induction
COMP108 Algorithmic Foundations Algorithm efficiency
CSE 311: Foundations of Computing
CSNB 143 Discrete Mathematical Structures
Hubert Chan (Chapters 1.6, 1.7, 4.1)
CSE373: Data Structures and Algorithms Lecture 2: Proof by Induction
CSE373: Data Structures and Algorithms Lecture 2: Proof by Induction
CS201: Data Structures and Discrete Mathematics I
Notes 9.5 – Mathematical Induction
Lesson 11 – Proof by induction
Copyright © Cengage Learning. All rights reserved.
Applied Discrete Mathematics Week 9: Integer Properties
Lecture 3.1: Mathematical Induction
Induction (Section 3.3).
Follow me for a walk through...
Advanced Analysis of Algorithms
COMP108 Algorithmic Foundations Searching
To prove by induction that n! > 2n for n > 3, n  N
Mathematical Induction
Follow me for a walk through...
COMP108 Algorithmic Foundations Searching
Lecture 3.1: Mathematical Induction
11.4 Mathematical Induction
COMP108 Algorithmic Foundations Mathematical Induction
Presentation transcript:

Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Mathematical Induction Prudence Wong

Algorithmic Foundations COMP108 Which Ball is Heavier? 9 balls look identically the same but 1 is heavier than the rest balance scale How to find the heavier one by weighing 2 times only?

Algorithmic Foundations COMP108 3 (Induction) Learning outcomes  Understand the concept of Induction  Able to prove by Induction

Algorithmic Foundations COMP108 4 (Induction) Analysis of Algorithms After designing an algorithm, we analyze it.  Proof of correctness: show that the algorithm gives the desired result  Time complexity analysis: find out how fast the algorithm runs  Space complexity analysis: find out how much memory space the algorithm requires  Look for improvement: can we improve the algorithm to run faster or use less memory? is it best possible?

Algorithmic Foundations COMP108 5 (Induction) A typical analysis technique Induction  technique to prove that a property holds for all natural numbers (or for all members of an infinite sequence) E.g., To prove 1+2+…+n = n(n+1)/2  +ve integers n However, this isn't a proof and we cannot enumerate over all possible numbers.  Induction nLHSRHSLHS = RHS? 111*2/2 = = 32*3/2 = = 63*4/2 = 6  for all

Algorithmic Foundations COMP108 Intuition – Long Row of Dominoes 6 (Induction)  How can we be sure each domino will fall?  Enough to ensure the 1 st domino will fall?  No. Two dominoes somewhere may not be spaced properly  Enough to ensure all are spaced properly?  No. We need the 1 st to fall  Both conditions required:  1 st will fall; & after the k th fall, k+1 st will also fall  then even infinitely long, all will fall

Algorithmic Foundations COMP108 7 (Induction) Induction To prove that a property holds for every positive integer n Two steps  Base case: Prove that the property holds for n = 1  Induction step: Prove that if the property holds for n = k (for some positive integer k), then the property holds for n = k + 1  Conclusion: The property holds for every positive integer n

Algorithmic Foundations COMP108 8 (Induction) Example To prove:  +ve integers n  Base case: When n=1, LHS=1, RHS= = 1. So, the property holds for n=1.  Induction hypothesis: Assume that the property holds when n=k for some integer k≥1. i.e., assume that  Induction step: When n=k+1, LHS becomes … + k + (k+1) RHS becomes  we want to prove Left hand side

Algorithmic Foundations COMP108 9 (Induction)  LHS= k+(k+1)  by hypothesis = RHS  So, property also holds for n=k+1  Conclusion: property holds for all +ve integers n Target: to proveInduction hypothesis Induction Step: When n=k+1

Algorithmic Foundations COMP (Induction) Conclusion We have proved 1. property holds for n=1 2. if property holds for n=k, then also holds for n=k+1 In other words,  holds for n=1 implies holds for n=2 (induction step)  holds for n=2 implies holds for n=3 (induction step)  holds for n=3 implies holds for n=4 (induction step)  and so on By principle of induction: holds for all +ve integers n

Algorithmic Foundations COMP (Induction) To prove n 3 +2n is divisible by 3  integers n  1 Example 2 Prove it by induction… nn 3 +2ndivisible by 3? 11+2 = = = = 72

Algorithmic Foundations COMP (Induction) To prove n 3 +2n is divisible by 3  integers n  1  Base case: When n=1, n 3 +2n=1+2=3, divisible by 3. So property holds for n=1.  Induction hypothesis: Assume property holds for n=k, for some +ve int k, i.e., assume k 3 +2k is divisible by 3  Induction step: When n=k+1, LHS becomes (k+1) 3 + 2(k+1) Example 2 Target: to prove (k+1) 3 +2(k+1) is divisible by 3

Algorithmic Foundations COMP (Induction)  Induction step: When n=k+1,  (k+1) 3 +2(k+1)= (k 3 +3k 2 +3k+1) + (2k+2) = (k 3 +2k) + 3(k 2 +k+1)  Property holds for n=k+1  By principle of induction: property holds  integers n  1 by hypothesis, divisible by 3divisible by 3 sum is divisible by 3 Target: to prove (k+1) 3 +2(k+1) is divisible by 3 Induction hypothesis k 3 +2k is divisible by 3

Algorithmic Foundations COMP (Induction) Example 3 To prove 2 n < n!  +ve integers n ≥ 4. Factorial: n! = n(n-1)(n-2) … *2*1 n2n2n n!LHS < RHS? Prove it by induction…

Algorithmic Foundations COMP (Induction) Example 3 To prove 2 n < n!  +ve integers n ≥ 4.  Base case: When n=4, LHS = 2 4 = 16, RHS = 4! = 4*3*2*1 = 24, LHS < RHS So, property holds for n=4  Induction hypothesis: Assume property holds for n=k for some integer k ≥ 4, i.e., assume 2 k < k!  Induction step: When n=k+1, LHS becomes 2 k+1, RHS becomes (k+1)! n! = n(n-1)(n-2) … *2*1 Target: to prove 2 k+1 <(k+1)!

Algorithmic Foundations COMP (Induction)  Induction step: When n=k+1,  LHS = 2 k+1 = 2*2 k < 2*k!  by hypothesis, 2 k < k!  RHS = (k+1)! = (k+1)*k! > 2*k! > LHS  because k+1>2  So, property holds for n=k+1  By principle of induction: property holds  +ve integers n≥4 Target: to prove 2 k+1 <(k+1)! Induction hypothesis 2 k <k!

Algorithmic Foundations COMP108 Example 3 17 (Induction) Why base case is n=4? When n=1,2 1 =2,1!=1 When n=2,2 2 =4,2!=2 When n=3,2 3 =8,3!=6 Property does not hold for n=1, 2, 3

Algorithmic Foundations COMP108 Challenges …

Algorithmic Foundations COMP (Induction) Exercise To prove  +ve int n ≥ 1. nLHSRHSLHS = RHS? 111*2*3/6 = = 52*3*5/6 = = 143*4*7/6 = = 304*5*9/6 = = 555*6*11/6 = 55 Prove it by induction…

Algorithmic Foundations COMP (Induction) Exercise To prove  Base case: when n=1, LHS = 1, RHS = =1=LHS  Induction hypothesis: Assume property holds for n=k  i.e., assume that  Induction step: When n=k+1, LHS becomes RHS becomes Target is to prove work on LHS & work on RHS and show that they reach the same expression

Algorithmic Foundations COMP (Induction) Induction Step: When n = k+1 LHS = k 2 + (k+1) 2  by hypothesis = RHS Therefore, the property holds for n=k+1. By the principle of induction, property holds  +ve integers Target: to prove Induction hypothesis:

Algorithmic Foundations COMP108 Prove that …+(2n-1) = n 2  +ve integers ≥ 1 (sum of the first n odd integers equals to n 2 ) 22 (Induction) Exercise 2 nLHSRHSLHS = RHS? = = 42 2 = = 93 2 = = = = = 25 Prove it by induction…

Algorithmic Foundations COMP (Induction) Exercise 2 Prove that …+(2n-1) = n 2  +ve integers ≥ 1  Base case: When n=1, LHS=2*1-1=1, RHS=1 2 =1  Induction hypothesis: Assume property holds for some integer k, i.e., assume …+(2k-1)=k 2  Induction step: When n=k+1, LHS becomes …+(2(k+1)-1) RHS becomes (k+1) 2 Target: to prove …+(2k-1)+(2(k+1)-1))=(k+1) 2

Algorithmic Foundations COMP108  Induction step: When n=k+1, LHS= …+(2k-1)+(2(k+1)-1) = k 2 +(2k+2-1) = k 2 +2k+1 RHS= (k+1) 2 = k 2 +2k+1 = LHS Therefore, property holds for n=k+1 By principle of induction, property holds for all +ve integers 24 (Induction) Target: to prove …+(2k-1)+(2(k+1)-1))=(k+1) 2 Induction hypothesis: …+(2k-1) =k 2

Algorithmic Foundations COMP108 More advanced …

Algorithmic Foundations COMP (Induction) Note The induction step means that if property holds for some integer k, then it also holds for k+1. It does NOT mean that the property must hold for k nor for k+1. Therefore, we MUST prove that property holds for some starting integer n 0, which is the base case. Missing the base case will make the proof fail.

Algorithmic Foundations COMP108 What's wrong with this? Claim: For all n, n=n+1  Assume the property holds for n=k, i.e., assume k = k+1  Induction Step:  Add 1 to both sides of the induction hypothesis  We get: k+1 = (k+1)+1, i.e., k+1 = k+2  The property holds for n=k+1 BUT, we know this isn't true, what's wrong? 27 (Induction) base case missing

Algorithmic Foundations COMP108 What about this? Claim: All comp108 students are of the same gender  Base case: Consider any group of ONE comp108 student. Same gender, of course.  Induction hypothesis: Assume that any group of k comp108 students are of same gender  Induction step: Consider any group of k+1 comp108 students… 28 (Induction)

Algorithmic Foundations COMP (Induction) k+1 A Take a student, say A k A Induction hypothesis: same gender k A B Induction hypothesis: same gender Swap a student, say B, with A So, A, B & other (k-1) students are of the same gender The argument works only when k>1. I.e., it fails when k=1 What’s wrong? B

Algorithmic Foundations COMP (Induction) Recall: Finding minimum input: a[1], a[2],..., a[n] M = a[1] i = 1 while (i <= n) do begin M = min(M, a[i]) ** i = i + 1 end output M Property: After each iteration of statement **, the value of M is min(a[1], …, a[i]) Consider at the end of the statement ** Base case: When i=1, M is min(a[1]) Induction hypothesis: Assume the property holds when i=k for some k≥1. Induction step: When i=k+1, If a[k+1] < min(a[1],…,a[k]), M is set to a[k+1], i.e., min(a[1],…,a[k+1]), Else, a[k+1] is not min, M is unchanged & M equals min(a[1],…,a[k+1])