Week 6 - Monday CS322.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms II
Advertisements

Week 6 - Wednesday CS322.
Mathematical Induction
Recursive Definitions and Structural Induction
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
Week 5 - Friday.  What did we talk about last time?  Sequences  Summation and production notation  Proof by induction.
Induction and recursion
Kavita Math231 Recursion and Iteration. Kavita Math231 We use Recursion when we have to perform a complex task that can be broken into the several subtasks.
Discrete Structures Chapter 2 Part B Mathematical Induction
Recursion.
CSE115/ENGR160 Discrete Mathematics 03/31/11
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
Recursion Lecture 17: Nov 11. Quiz int hello(int n) { if (n==0) return 0; else printf(“Hello World %d\n”,n); hello(n-1); } 1.What would the program do.
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.
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.
analysis, plug ‘n’ chug, & induction
Properties of the Integers: Mathematical Induction
Induction and recursion
Copyright © Cengage Learning. All rights reserved.
Copyright © Cengage Learning. All rights reserved. CHAPTER 11 ANALYSIS OF ALGORITHM EFFICIENCY ANALYSIS OF ALGORITHM EFFICIENCY.
Applied Discrete Mathematics Week 9: Relations
Advanced Counting Techniques
College Algebra Sixth Edition James Stewart Lothar Redlin Saleem Watson.
Mathematical Maxims and Minims, 1988
MATH 224 – Discrete Mathematics
Induction and recursion
Discrete Mathematics, 1st Edition Kevin Ferland
Mathematics Review Exponents Logarithms Series Modular arithmetic Proofs.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
1 Introduction to Abstract Mathematics Chapter 4: Sequences and Mathematical Induction Instructor: Hayk Melikya 4.1- Sequences. 4.2,
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
CSC201 Analysis and Design of Algorithms Asst.Proof.Dr.Surasak Mungsing Oct-151 Lecture 2: Definition of algorithm and Mathematical.
Foundations of Discrete Mathematics Chapters 5 By Dr. Dalia M. Gil, Ph.D.
Chapter 2 Mathematical preliminaries 2.1 Set, Relation and Functions 2.2 Proof Methods 2.3 Logarithms 2.4 Floor and Ceiling Functions 2.5 Factorial and.
Chapter 7 Advance Counting Techniques. Content Recurrence relations Generating function The principle of inclusion-exclusion.
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
Induction Proof. Well-ordering A set S is well ordered if every subset has a least element. [0, 1] is not well ordered since (0,1] has no least element.
Proofs, Induction and Recursion Basic Proof Techniques Mathematical Induction Recursive Functions and Recurrence Relations.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
Week 6 - Friday.  What did we talk about last time?  Solving recurrence relations.
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.
ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.
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.
RECURRENCE Sequence Recursively defined sequence
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.
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
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.
Section 1.7. Definitions A theorem is a statement that can be shown to be true using: definitions other theorems axioms (statements which are given as.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Mathematical Induction And Recursion Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
Chapter 5 1. Chapter Summary  Mathematical Induction  Strong Induction  Recursive Definitions  Structural Induction  Recursive Algorithms.
Induction and recursion
Mathematical Induction Recursion
Chapter 5 Induction and Recursion
Copyright © Cengage Learning. All rights reserved.
Applied Discrete Mathematics Week 9: Integer Properties
1A Recursively Defined Functions
Copyright © Cengage Learning. All rights reserved.
Mathematical Induction
Week 6 - Wednesday CS322.
Presentation transcript:

Week 6 - Monday CS322

Last time What did we talk about last time? Proof by induction Strong induction

Questions?

Logical warmup Revenge of the hats 20 prisoners are scheduled to be executed tomorrow They will be lined up in a row facing the same direction, each randomly wearing a white hat or a black hat Thus, one prisoner can see 19 prisoners, the next can see 18 prisoners, etc. Tomorrow, each prisoner, in order, starting with the last (who can see the other 19) will be asked the color of his hat He can answer "white" or "black" If he answers correctly, he is spared, otherwise he is shot If anyone answers something other than "white" or "black," everyone is killed immediately Since the prisoners were told the scenario a day a head of time, what strategy can they develop to save the maximum number of prisoners?

More Induction Examples

Divisibility Prove that, for all integers n ≥ 1, 22n – 1 is divisible by 3 Hint: Use induction

Inequality Prove that, for all real number n ≥ 3, 2n + 1 < 2n Hint: Use induction

Fibonacci The Fibonacci sequence is 1, 1, 2, 3, 5, 8, … We can define it (recursively) as follows: F1 = F2 = 1 Fn = Fn-1 + Fn-2, n ≥ 2 Prove that, for all integers n ≥ 1, F4n is divisible by 3 Hint: Use induction

Strong Induction

Strong induction There are situations where we need more than the fact that the kth element maintains some property to prove the k + 1st element has the same property Strong induction allows us to use the kth element, the k-1st, element, the k-2nd element, and so on This is usually most helpful when the subterms you are doing induction on are of unknown size

Proof by strong induction To prove a statement of the following form: n  Z, where n a, property P(n) is true Use the following steps: Basis Step: Show that the property is true for P(a), P(a+1), … P(b-1) , P(b), where a ≤ b, bZ Induction Step: Suppose that the property is true for some a ≤ i < k, where k  Z and k > b Now, show that, with that assumption, the property is also true for k

Example Theorem: For all integers n  2, n is divisible by a prime Proof: Basis step: (n = 2) The property is true for n = 2 because 2 is divisible by 2 Induction step: Assume that all numbers i where 2 ≤ i < k are divisible by a prime, where k > 2 and k  Z Case 1: k is prime If k is prime, k = k∙1, therefore k is divisible by a prime, namely itself Case 2: k is composite If k is composite, k = a∙b, where a,b  Z and 2 ≤ a < k and 2 ≤ b < k By the induction hypothesis, a is divisible by some prime p Thus, k = p∙c∙b = p∙d and k is divisible by prime p Since we have shown the basis step and induction step of strong mathematical induction, the claim is true QED

Example Theorem: It takes exactly n-1 steps to assemble a jigsaw puzzle with n pieces Proof: Basis step: (n = 1) A puzzle with 1 piece takes 0 steps to put together Induction step: Assume it takes i – 1 steps to put together puzzles of size i where 1 ≤ i < k, where k > 1 and k  Z The last step in a puzzle of size k is putting together a subpuzzle of size j and a subpuzzle of size k – j where j  Z and 1 ≤ j < k and 1 ≤ k - j < k By the induction hypothesis, it took j – 1 steps to put together one subpuzzle and k – j – 1 steps to put together the other Thus, the total number of steps is j – 1 + k + j – 1 + 1 = k – 1 steps Since we have shown the basis step and induction step of strong mathematical induction, the claim is true QED

Well-Ordering Principle for Integers It turns out that the concept of truth through mathematical induction is equivalent to another principle Well-Ordering Principle for the Integers: Let S be a set containing one or more integers all of which are greater than some fixed integer. Then S has a least element.

Recursion In order to understand recursion, you must first understand recursion.

Recursively defined sequences As you've seen with Fibonacci, it's possible to define a sequence recursively This is called a recurrence relation The initial conditions give the starting point Example: Initial conditions c0 = 1 c1 = 2 Recurrence relation ck = ck-1 + kck-2 + 1, for all integers k  2 Find c2, c3, and c4

Writing recurrence relations in multiple ways Consider the following recurrence relation: sk = 3sk-1 – 1, for all integers k  1 Now consider this one: sk+1 = 3sk – 1, for all integers k  0 Both recurrence relations have the same meaning

Differences in initial conditions Even if the recurrence relations are equivalent, different initial conditions can cause a different sequence Example: ak = 3ak-1, for all integers k  2 a1 = 2 bk = 3bk-1, for all integers k  2 b1 = 1 Find a1, a2, and a3 Find b1, b2, and b3

Practice Using just your wits, you should be able to figure out recursive definitions for many sequences Give a recurrence relation for positive even integers: 2, 4, 6, 8, … Give a recurrence relation for the triangular numbers: 1, 3, 6, 10, 15, … Give a recurrence relation for the perfect squares: 1, 4, 9, 16, 25, … Give a recurrence relation for factorial: 1, 2, 6, 24, 120, 720 …

The proof is on fire Perhaps you believe that you have the correct recurrence relation for perfect squares Can you prove it? Hint: Use mathematical induction Recursion and induction and two sides of the same coin The right cross and the left jab, if you will, of the computer scientist's arsenal

Tower of Hanoi Imagine that you have a tower of disks such that each is smaller than the one it rests on Rules: There are 3 pegs, and all the disks are on peg 1 No two disks are the same size A larger disk may not be placed on a smaller disk Disks can only be moved one at a time Move all the disks to peg 3

Power of Hanoi What's the smallest number of moves needed to move the disks? Consider the following algorithm for moving k disks from the starting pole to the ending pole: (Recursively) transfer the top k – 1 disks from the starting pole to the temporary pole Move the bottom disk from the starting pole to the ending pole (Recursively) move the top k – 1 disks from the temporary pole to the ending pole

Tower of annoy How do we represent the running time of this algorithm recursively? We have to (recursively) move k – 1 disks, then a single disk, then (recursively) another k – 1 disks mk = mk-1 + 1 + mk-1 or mk = 2mk-1 + 1 Clearly, it takes 1 move to move a single disk, so m1 = 1 Find m2, m3, m4, and m5

Fibonacci We all know and love Fibonacci by now Recall that it is supposed to model rabbit populations For the first month of their lives, they cannot reproduce After that, they reproduce every single month

Fibonacci rules From this information about rabbit physiology (which is a simplification, of course) we can think about pairs of rabbits At time k, rabbits born at time k – 1 will not reproduce Any rabbits born at k – 2 or earlier will, however So, we assume that all the rabbits from time k – 2 have doubled between time k – 1 and k Thus, our recurrence relation is: Fk = Fk – 1 + Fk – 2, k  2 Assuming one starting pair of rabbits, our initial conditions are: F0 = 1 F1 = 1

Compound interest It's boring, but useful Interest is compounded based on some period of time We can define the value recursively Let i is the annual percentage rate (APR) of interest Let m be the number of times per year the interest is compounded Thus, the total value of the investment at the kth period is Pk = Pk-1 + Pk-1(i/m), k  1 P0 = initial principle

Solving Recurrence Relations

Recursion … is confusing We don't naturally think recursively (but perhaps you can raise your children to think that way?) As it turns out, the total number of moves needed to solve the Tower of Hanoi for n disks is 2n – 1 Likewise, with an interest rate of i, a principle of P0, and m periods per year, the investment will yield Po(i/m + 1)k after k periods

Finding explicit formulas by iteration Consequently, we want to be able to turn recurrence relations into explicit formulas whenever possible Often, the simplest way is to find these formulas by iteration The technique of iteration relies on writing out many expansions of the recursive sequence and looking for patterns That's it

Iteration example Find a pattern for the following recurrence relation: ak = ak-1 + 2 a0 = 1 Start at the first term Write the next below Do not combine like terms! Leave everything in expanded form until patterns emerge

Arithmetic sequence In principle, we should use mathematical induction to prove that the explicit formula we guess actually holds The previous example (odd integers) shows a simple example of an arithmetic sequence These are recurrences of the form: ak = ak-1 + d, for integers k ≥ 1 Note that these recurrences are always equivalent to an = a0 + dn, for all integers n ≥ 0 Let's prove it

Geometric sequence Find a pattern for the following recurrence relation: ak = rak-1, k ≥ 1 a0 = a Again, start at the first term Write the next below Do not combine like terms! Leave everything in expanded form until patterns emerge

Geometric sequence It appears that any geometric sequence with the following form ak = rak-1, k ≥ 1 is equivalent to an = a0rn, for all integers n ≥ 0 This result applies directly to compound interest calculation Let's prove it

Employing outside formulas Sure, intelligent pattern matching gets you a long way However, it is sometimes necessary to substitute in some known formula to simplify a series of terms Recall Geometric series: 1 + r + r2 + … + rn = (rn+1 – 1)/(r – 1) Arithmetic series: 1 + 2 + 3 + … + n = n(n + 1)/2

Tower of Hanoi solution Find a pattern for the following recurrence relation: mk = 2mk-1 + 1, k ≥ 2 m1 = 1 Again, start at the first term Write the next below Do not combine like terms! Leave everything in expanded form until patterns emerge Use the arithmetic series or geometric series equations as needed

How many edges are in a complete graph? In a complete graph, every node is connected to every other node If we want to make a complete graph with k nodes, we can take a complete graph with k – 1 nodes, add a new node, and add k – 1 edges (so that all the old nodes are connected to the new node Recursively, this means that the number of edges in a complete graph is sk = sk-1 + (k – 1), k ≥ 2 s1 = 0 (no edges in a graph with a single node) Use iteration to solve this recurrence relation

Mistakes were made! You might make a mistake when you are solving by iteration Consider the following recursive definition ck = 2ck-1 + k, k ≥ 1 c0 = 1 Careless analysis might lead you to the explicit formula cn = 2n + n, n ≥ 0 How would this be caught in a proof by induction verification?

Solving Recurrence Relations

Recursion … is confusing We don't naturally think recursively (but perhaps you can raise your children to think that way?) As it turns out, the total number of moves needed to solve the Tower of Hanoi for n disks is 2n – 1 Likewise, with an interest rate of i, a principle of P0, and m periods per year, the investment will yield Po(i/m + 1)k after k periods

Finding explicit formulas by iteration Consequently, we want to be able to turn recurrence relations into explicit formulas whenever possible Often, the simplest way is to find these formulas by iteration The technique of iteration relies on writing out many expansions of the recursive sequence and looking for patterns That's it

Iteration example Find a pattern for the following recurrence relation: ak = ak-1 + 2 a0 = 1 Start at the first term Write the next below Do not combine like terms! Leave everything in expanded form until patterns emerge

Arithmetic sequence In principle, we should use mathematical induction to prove that the explicit formula we guess actually holds The previous example (odd integers) shows a simple example of an arithmetic sequence These are recurrences of the form: ak = ak-1 + d, for integers k ≥ 1 Note that these recurrences are always equivalent to an = a0 + dn, for all integers n ≥ 0 Let's prove it

Geometric sequence Find a pattern for the following recurrence relation: ak = rak-1, k ≥ 1 a0 = a Again, start at the first term Write the next below Do not combine like terms! Leave everything in expanded form until patterns emerge

Geometric sequence It appears that any geometric sequence with the following form ak = rak-1, k ≥ 1 is equivalent to an = a0rn, for all integers n ≥ 0 This result applies directly to compound interest calculation Let's prove it

Employing outside formulas Sure, intelligent pattern matching gets you a long way However, it is sometimes necessary to substitute in some known formula to simplify a series of terms Recall Geometric series: 1 + r + r2 + … + rn = (rn+1 – 1)/(r – 1) Arithmetic series: 1 + 2 + 3 + … + n = n(n + 1)/2

Tower of Hanoi solution Find a pattern for the following recurrence relation: mk = 2mk-1 + 1, k ≥ 2 m1 = 1 Again, start at the first term Write the next below Do not combine like terms! Leave everything in expanded form until patterns emerge Use the arithmetic series or geometric series equations as needed

How many edges are in a complete graph? In a complete graph, every node is connected to every other node If we want to make a complete graph with k nodes, we can take a complete graph with k – 1 nodes, add a new node, and add k – 1 edges (so that all the old nodes are connected to the new node Recursively, this means that the number of edges in a complete graph is sk = sk-1 + (k – 1), k ≥ 2 s1 = 0 (no edges in a graph with a single node) Use iteration to solve this recurrence relation

Mistakes were made! You might make a mistake when you are solving by iteration Consider the following recursive definition ck = 2ck-1 + k, k ≥ 1 c0 = 1 Careless analysis might lead you to the explicit formula cn = 2n + n, n ≥ 0 How would this be caught in a proof by induction verification?

Upcoming

Next time… Second-order linear homogeneous recurrence relations with constant coefficients Generalized recursion Introduction to set theory

Reminders Homework 3 is due tonight! Homework 4 is due on Friday Read Chapter 6