Applied Discrete Mathematics Week 7: Computation

Slides:



Advertisements
Similar presentations
Fall 2002CMSC Discrete Structures1 Now it’s Time for… RecurrenceRelations.
Advertisements

Discrete Mathematics Math 6A Homework 9 Solution.
Recursive Definitions and Structural Induction
Recursively Defined Functions
February 19, 2015Applied Discrete Mathematics Week 4: Number Theory 1 The Growth of Functions Question: If f(x) is O(x 2 ), is it also O(x 3 )? Yes. x.
Week #10 – 28/30 October and 1 November 2002 Prof. Marie desJardins
CS 2210 (22C:19) Discrete Structures Advanced Counting
April 9, 2015Applied Discrete Mathematics Week 9: Relations 1 Solving Recurrence Relations Another Example: Give an explicit formula for the Fibonacci.
CSE115/ENGR160 Discrete Mathematics 04/19/12 Ming-Hsuan Yang UC Merced 1.
CSE115/ENGR160 Discrete Mathematics 04/21/11 Ming-Hsuan Yang UC Merced 1.
Algorithm Design Techniques: Induction Chapter 5 (Except Sections 5.6 and 5.7)
Algorithm Design Techniques: Induction Chapter 5 (Except Section 5.6)
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
6.Advanced Counting Techniques 1 Copyright M.R.K. Krishna Rao 2003 Ch 6. Recurrence Relations A recurrence relation for the sequence {a n } is an equation.
Induction and recursion
Analysis of Recursive Algorithms October 29, 2014
February 17, 2015Applied Discrete Mathematics Week 3: Algorithms 1 Double Summations Table 2 in 4 th Edition: Section th Edition: Section th.
Applied Discrete Mathematics Week 9: Relations
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
DISCRETE MATHEMATICS I CHAPTER 11 Dr. Adam Anthony Spring 2011 Some material adapted from lecture notes provided by Dr. Chungsim Han and Dr. Sam Lomonaco.
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
CSE 2813 Discrete Structures Recurrence Relations Section 6.1.
R. Johnsonbaugh Discrete Mathematics 7 th edition, 2009 Chapter 7 Recurrence Relations Instructor Tianping Shuai.
Sequences and Summations
Recurrence Relations: Selected Exercises
Fall 2002CMSC Discrete Structures1 Enough Mathematical Appetizers! Let us look at something more interesting: Algorithms.
MCA-2012Data Structure1 Algorithms Rizwan Rehman CCS, DU.
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Lecture 4,5 Mathematical Induction and Fibonacci Sequences.
Sequences and Summations Section 2.4. Section Summary Sequences. – Examples: Geometric Progression, Arithmetic Progression Recurrence Relations – Example:
Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.
ADVANCED ALGORITHMS REVIEW OF ANALYSIS TECHNIQUES (UNIT-1)
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.
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
Chapter 2 1. Chapter Summary Sets The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions and sequences.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Section Recursion  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.
Fall 2002CMSC Discrete Structures1 Chapter 3 Sequences Mathematical Induction Recursion Recursion.
Chapter 4: Induction and Recursion
CMSC Discrete Structures
Applied Discrete Mathematics Week 2: Functions and Sequences
Modeling with Recurrence Relations
Applied Discrete Mathematics Week 11: Relations
The Growth of Functions
Induction and Recursion
Recursively Defined Functions
Applied Discrete Mathematics Week 3: Algorithms
Discrete Math (2) Haiming Chen Associate Professor, PhD
Enough Mathematical Appetizers!
Computation.
Enough Mathematical Appetizers!
Applied Discrete Mathematics Week 6: Computation
Applied Discrete Mathematics Week 9: Integer Properties
Counting Discrete Mathematics.
CS 2210 Discrete Structures Advanced Counting
CMSC Discrete Structures
Solving Recurrence Relations
CMSC 203, Section 0401 Discrete Structures Fall 2004 Matt Gaston
Enough Mathematical Appetizers!
Enough Mathematical Appetizers!
CMSC Discrete Structures
Recurrence Relations Discrete Structures.
Mathematical Induction
Chapter 7 Advanced Counting Techniques
Recurrence Relations.
ICS 253: Discrete Structures I
Recursion.
Presentation transcript:

Applied Discrete Mathematics Week 7: Computation Useful Rules for Big-O For any polynomial f(x) = anxn + an-1xn-1 + … + a0, where a0, a1, …, an are real numbers, f(x) is O(xn). If f1(x) is O(g(x)) and f2(x) is O(g(x)), then (f1 + f2)(x) is O(g(x)). If f1(x) is O(g1(x)) and f2(x) is O(g2(x)), then (f1 + f2)(x) is O(max(g1(x), g2(x))) If f1(x) is O(g1(x)) and f2(x) is O(g2(x)), then (f1f2)(x) is O(g1(x) g2(x)). October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Applied Discrete Mathematics Week 7: Computation Complexity Examples What does the following algorithm compute? procedure who_knows(a1, a2, …, an: integers) who_knows := 0 for i := 1 to n-1 for j := i+1 to n if |ai – aj| > who_knows then who_knows := |ai – aj| {who_knows is the maximum difference between any two numbers in the input sequence} Comparisons: n-1 + n-2 + n-3 + … + 1 = (n – 1)n/2 = 0.5n2 – 0.5n Time complexity is O(n2). October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Applied Discrete Mathematics Week 7: Computation Complexity Examples Another algorithm solving the same problem: procedure max_diff(a1, a2, …, an: integers) min := a1 max := a1 for i := 2 to n if ai < min then min := ai else if ai > max then max := ai max_diff := max - min Comparisons (worst case): 2n - 2 Time complexity is O(n). October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Induction and Recursion Now it’s Time for… Induction and Recursion October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Applied Discrete Mathematics Week 7: Computation Recurrence Relations A recurrence relation for the sequence {an} is an equation that expresses an is terms of one or more of the previous terms of the sequence, namely, a0, a1, …, an-1, for all integers n with n  n0, where n0 is a nonnegative integer. A sequence is called a solution of a recurrence relation if its terms satisfy the recurrence relation. October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Applied Discrete Mathematics Week 7: Computation Recurrence Relations In other words, a recurrence relation is like a recursively defined sequence, but without specifying any initial values (initial conditions). Therefore, the same recurrence relation can have (and usually has) multiple solutions. If both the initial conditions and the recurrence relation are specified, then the sequence is uniquely determined. October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Applied Discrete Mathematics Week 7: Computation Recurrence Relations Example: Consider the recurrence relation an = 2an-1 – an-2 for n = 2, 3, 4, … Is the sequence {an} with an=3n a solution of this recurrence relation? For n  2 we see that 2an-1 – an-2 = 2(3(n – 1)) – 3(n – 2) = 3n = an. Therefore, {an} with an=3n is a solution of the recurrence relation. October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Applied Discrete Mathematics Week 7: Computation Recurrence Relations Is the sequence {an} with an=5 a solution of the same recurrence relation? For n  2 we see that 2an-1 – an-2 = 25 - 5 = 5 = an. Therefore, {an} with an=5 is also a solution of the recurrence relation. October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Modeling with Recurrence Relations Example: Someone deposits $10,000 in a savings account at a bank yielding 5% per year with interest compounded annually. How much money will be in the account after 30 years? Solution: Let Pn denote the amount in the account after n years. How can we determine Pn on the basis of Pn-1? October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Modeling with Recurrence Relations We can derive the following recurrence relation: Pn = Pn-1 + 0.05Pn-1 = 1.05Pn-1. The initial condition is P0 = 10,000. Then we have: P1 = 1.05P0 P2 = 1.05P1 = (1.05)2P0 P3 = 1.05P2 = (1.05)3P0 … Pn = 1.05Pn-1 = (1.05)nP0 We now have a formula to calculate Pn for any natural number n and can avoid the iteration. October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Modeling with Recurrence Relations Let us use this formula to find P30 under the initial condition P0 = 10,000: P30 = (1.05)3010,000 = 43,219.42 After 30 years, the account contains $43,219.42. October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Modeling with Recurrence Relations Another example: Let an denote the number of bit strings of length n that do not have two consecutive 0s (“valid strings”). Find a recurrence relation and give initial conditions for the sequence {an}. Solution: Idea: The number of valid strings equals the number of valid strings ending with a 0 plus the number of valid strings ending with a 1. October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Modeling with Recurrence Relations Let us assume that n  3, so that the string contains at least 3 bits. Let us further assume that we know the number an-1 of valid strings of length (n – 1) and the number an-2 of valid strings of length (n – 2). Then how many valid strings of length n are there, if the string ends with a 1? There are an-1 such strings, namely the set of valid strings of length (n – 1) with a 1 appended to them. Note: Whenever we append a 1 to a valid string, that string remains valid. October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Modeling with Recurrence Relations Now we need to know: How many valid strings of length n are there, if the string ends with a 0? Valid strings of length n ending with a 0 must have a 1 as their (n – 1)st bit (otherwise they would end with 00 and would not be valid). And what is the number of valid strings of length (n – 1) that end with a 1? We already know that there are an-1 strings of length n that end with a 1. Therefore, there are an-2 strings of length (n – 1) that end with a 1. October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Modeling with Recurrence Relations So there are an-2 valid strings of length n that end with a 0 (all valid strings of length (n – 2) with 10 appended to them). As we said before, the number of valid strings is the number of valid strings ending with a 0 plus the number of valid strings ending with a 1. That gives us the following recurrence relation: an = an-1 + an-2 October 18, 2018 Applied Discrete Mathematics Week 7: Computation

Modeling with Recurrence Relations What are the initial conditions? a1 = 2 (0 and 1) a2 = 3 (01, 10, and 11) a3 = a2 + a1 = 3 + 2 = 5 a4 = a3 + a2 = 5 + 3 = 8 a5 = a4 + a3 = 8 + 5 = 13 … This sequence satisfies the same recurrence relation as the Fibonacci sequence. Since a1 = f3 and a2 = f4, we have an = fn+2. October 18, 2018 Applied Discrete Mathematics Week 7: Computation