Top Banner
Fall 2002 CMSC 203 - Discrete Structures 1 Now it’s Time for… Now it’s Time for… Recurrenc Recurrenc e e Relations Relations
27

Chapter 6 (.ppt file)

Jan 12, 2017

Download

Documents

buitu
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 1

Now it’s Time for…Now it’s Time for…

RecurrenRecurrencece

RelationsRelations

Page 2: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 2

Recurrence RelationsRecurrence RelationsA A recurrence relationrecurrence relation for the sequence {a for the sequence {ann} } is an equation that expresses ais an equation that expresses ann is terms of is terms of one or more of the previous terms of the one or more of the previous terms of the sequence, namely, asequence, namely, a00, a, a11, …, a, …, an-1n-1, for all , for all integers n with integers n with n n n n00, where n, where n00 is a nonnegative integer. is a nonnegative integer.

A sequence is called a A sequence is called a solutionsolution of a of a recurrence relation if it terms satisfy the recurrence relation if it terms satisfy the recurrence relation.recurrence relation.

Page 3: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 3

Recurrence RelationsRecurrence Relations

In other words, a recurrence relation is like a In other words, a recurrence relation is like a recursively defined sequence, but recursively defined sequence, but without without specifying any initial values (initial specifying any initial values (initial conditions)conditions)..

Therefore, the same recurrence relation can Therefore, the same recurrence relation can have (and usually has) have (and usually has) multiple solutionsmultiple solutions..

If If bothboth the initial conditions and the recurrence the initial conditions and the recurrence relation are specified, then the sequence is relation are specified, then the sequence is uniquely uniquely determined.determined.

Page 4: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 4

Recurrence RelationsRecurrence RelationsExample:Example: Consider the recurrence relation Consider the recurrence relation aann = 2a = 2an-1n-1 – a – an-2n-2 for n = 2, 3, 4, … for n = 2, 3, 4, …

Is the sequence {aIs the sequence {ann} with a} with ann=3n a solution of =3n a solution of this recurrence relation?this recurrence relation?For n For n 2 we see that 2 we see that 2a2an-1n-1 – a – an-2n-2 = 2(3(n – 1)) – 3(n – 2) = 3n = a = 2(3(n – 1)) – 3(n – 2) = 3n = ann..Therefore, {aTherefore, {ann} with a} with ann=3n is a solution of the =3n is a solution of the recurrence relation.recurrence relation.

Page 5: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 5

Recurrence RelationsRecurrence Relations

Is the sequence {aIs the sequence {ann} with a} with ann=5 a solution of =5 a solution of the same recurrence relation?the same recurrence relation?For n For n 2 we see that 2 we see that 2a2an-1n-1 – a – an-2n-2 = 2 = 25 - 5 = 5 = a5 - 5 = 5 = ann..Therefore, {aTherefore, {ann} with a} with ann=5 is also a solution of =5 is also a solution of the recurrence relation.the recurrence relation.

Page 6: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 6

Modeling with Recurrence Modeling with Recurrence RelationsRelations

Example:Example: Someone deposits $10,000 in a savings Someone deposits $10,000 in a savings account at a bank yielding 5% per year with account at a bank yielding 5% per year with interest compounded annually. How much interest compounded annually. How much money will be in the account after 30 years?money will be in the account after 30 years?Solution:Solution:Let PLet Pnn denote the amount in the account after denote the amount in the account after n years.n years.How can we determine PHow can we determine Pnn on the basis of P on the basis of Pn-1n-1??

Page 7: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 7

Modeling with Recurrence Modeling with Recurrence RelationsRelationsWe can derive the following We can derive the following recurrence relationrecurrence relation::

PPnn = P = Pn-1n-1 + 0.05P + 0.05Pn-1n-1 = 1.05P = 1.05Pn-1n-1..The initial condition is PThe initial condition is P00 = 10,000. = 10,000.Then we have:Then we have:PP11 = 1.05P = 1.05P00 PP22 = 1.05P = 1.05P11 = (1.05) = (1.05)22PP00

PP33 = 1.05P = 1.05P22 = (1.05) = (1.05)33PP00……PPnn = 1.05P = 1.05Pn-1n-1 = (1.05) = (1.05)nnPP00

We now have a We now have a formulaformula to calculate P to calculate Pnn for any for any natural number n and can avoid the iteration.natural number n and can avoid the iteration.

Page 8: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 8

Modeling with Recurrence Modeling with Recurrence RelationsRelations

Let us use this formula to find PLet us use this formula to find P3030 under the under theinitial condition Pinitial condition P00 = 10,000: = 10,000:

PP3030 = (1.05) = (1.05)303010,000 = 43,219.4210,000 = 43,219.42

After 30 years, the account contains After 30 years, the account contains $43,219.42.$43,219.42.

Page 9: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 9

Modeling with Recurrence Modeling with Recurrence RelationsRelations

Another example:Another example: Let aLet ann denote the number of bit strings of denote the number of bit strings of length n that do not have two consecutive 0s length n that do not have two consecutive 0s (“valid strings”). Find a recurrence relation (“valid strings”). Find a recurrence relation and give initial conditions for the sequence and give initial conditions for the sequence {a{ann}.}.

Solution:Solution:Idea: The number of valid strings equals the Idea: The number of valid strings equals the number of valid strings ending with a 0 plus number of valid strings ending with a 0 plus the number of valid strings ending with a 1.the number of valid strings ending with a 1.

Page 10: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 10

Modeling with Recurrence Modeling with Recurrence RelationsRelations

Let us assume that n Let us assume that n 3, so that the string 3, so that the string contains at least 3 bits.contains at least 3 bits.Let us further assume that we know the Let us further assume that we know the number anumber an-1n-1 of valid strings of length (n – 1). of valid strings of length (n – 1). Then how many valid strings of length n are Then how many valid strings of length n are there, if the string ends with a 1?there, if the string ends with a 1?There are aThere are an-1n-1 such strings, namely the set of such strings, namely the set of valid strings of length (n – 1) with a 1 valid strings of length (n – 1) with a 1 appended to them.appended to them.Note:Note: Whenever we append a 1 to a valid Whenever we append a 1 to a valid string, that string remains valid.string, that string remains valid.

Page 11: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 11

Modeling with Recurrence Modeling with Recurrence RelationsRelations

Now we need to know: How many valid strings Now we need to know: How many valid strings of length n are there, if the string ends with a of length n are there, if the string ends with a 00??Valid strings of length n ending with a 0 Valid strings of length n ending with a 0 must must have a 1 as their (n – 1)st bithave a 1 as their (n – 1)st bit (otherwise they (otherwise they would end with 00 and would not be valid).would end with 00 and would not be valid).And what is the number of valid strings of length And what is the number of valid strings of length (n – 1) that end with a 1?(n – 1) that end with a 1?We already know that there are aWe already know that there are an-1n-1 strings of strings of length n that end with a 1.length n that end with a 1.Therefore, there are aTherefore, there are an-2n-2 strings of length (n – 1) strings of length (n – 1) that end with a 1.that end with a 1.

Page 12: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 12

Modeling with Recurrence Modeling with Recurrence RelationsRelations

So there are aSo there are an-2n-2 valid strings of length n that valid strings of length n that end with a 0 (all valid strings of length (n – 2) end with a 0 (all valid strings of length (n – 2) with 10 appended to them).with 10 appended to them).

As we said before, the number of valid strings As we said before, the number of valid strings is the number of valid strings ending with a 0 is the number of valid strings ending with a 0 plus the number of valid strings ending with a plus the number of valid strings ending with a 1.1.

That gives us the following That gives us the following recurrence recurrence relationrelation::aann = a = an-1n-1 + a + an-2n-2

Page 13: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 13

Modeling with Recurrence Modeling with Recurrence RelationsRelations

What are the What are the initial conditionsinitial conditions??aa11 = 2 (0 and 1) = 2 (0 and 1)aa22 = 3 (01, 10, and 11) = 3 (01, 10, and 11)aa33 = a = a22 + a + a11 = 3 + 2 = 5 = 3 + 2 = 5aa44 = a = a33 + a + a22 = 5 + 3 = 8 = 5 + 3 = 8aa55 = a = a44 + a + a33 = 8 + 5 = 13 = 8 + 5 = 13……This sequence satisfies the same recurrence This sequence satisfies the same recurrence relation as the relation as the Fibonacci sequenceFibonacci sequence..Since aSince a11 = f = f33 and a and a22 = f = f44, we have a, we have ann = f = fn+2n+2..

Page 14: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 14

Solving Recurrence RelationsSolving Recurrence Relations

In general, we would prefer to have an In general, we would prefer to have an explicit formulaexplicit formula to compute the value of a to compute the value of ann rather than conducting n iterations.rather than conducting n iterations.For one class of recurrence relations, we can For one class of recurrence relations, we can obtain such formulas in a systematic way.obtain such formulas in a systematic way.Those are the recurrence relations that Those are the recurrence relations that express the terms of a sequence as express the terms of a sequence as linear linear combinationscombinations of previous terms. of previous terms.

Page 15: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 15

Solving Recurrence RelationsSolving Recurrence RelationsDefinition:Definition: A linear homogeneous recurrence A linear homogeneous recurrence relation of degree k with constant coefficients is relation of degree k with constant coefficients is a recurrence relation of the form:a recurrence relation of the form:aann = c = c11aan-1n-1 + c + c22aan-2n-2 + … + c + … + ckkaan-kn-k,,Where cWhere c11, c, c22, …, c, …, ckk are real numbers, and c are real numbers, and ckk 0. 0.

A sequence satisfying such a recurrence A sequence satisfying such a recurrence relation is uniquely determined by the relation is uniquely determined by the recurrence relation and the k initial conditionsrecurrence relation and the k initial conditionsaa00 = C = C00, a, a11 = C = C11, a, a22 = C = C22, …, a, …, ak-1k-1 = C = Ck-1k-1..

Page 16: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 16

Solving Recurrence RelationsSolving Recurrence RelationsExamples:Examples:The recurrence relation PThe recurrence relation Pnn = (1.05)P = (1.05)Pn-1n-1is a linear homogeneous recurrence relation of is a linear homogeneous recurrence relation of degree onedegree one..The recurrence relation fThe recurrence relation fnn = f = fn-1n-1 + f + fn-2n-2is a linear homogeneous recurrence relation of is a linear homogeneous recurrence relation of degree twodegree two..The recurrence relation aThe recurrence relation ann = a = an-5n-5is a linear homogeneous recurrence relation of is a linear homogeneous recurrence relation of degree fivedegree five..

Page 17: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 17

Solving Recurrence RelationsSolving Recurrence RelationsBasically, when solving such recurrence Basically, when solving such recurrence relations, we try to find solutions of the form relations, we try to find solutions of the form aann = r= rnn, where r is a constant., where r is a constant.aann = r = rnn is a solution of the recurrence relation is a solution of the recurrence relationaann = c = c11aan-1n-1 + c + c22aan-2n-2 + … + c + … + ckkaan-kn-k if and only if if and only ifrrnn = c = c11rrn-1 n-1 + c+ c22rrn-2 n-2 + … + c+ … + ckkrrn-kn-k..Divide this equation by rDivide this equation by rn-kn-k and subtract the and subtract the right-hand side from the left:right-hand side from the left:rrkk - c - c11rrk-1 k-1 - c- c22rrk-2 k-2 - … - c- … - ck-1k-1r - cr - ckk = 0 = 0This is called the This is called the characteristic equationcharacteristic equation of of the recurrence relation.the recurrence relation.

Page 18: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 18

Solving Recurrence RelationsSolving Recurrence RelationsThe solutions of this equation are called the The solutions of this equation are called the characteristic rootscharacteristic roots of the recurrence relation. of the recurrence relation.Let us consider linear homogeneous recurrence Let us consider linear homogeneous recurrence relations of relations of degree twodegree two..Theorem:Theorem: Let c Let c11 and c and c22 be real numbers. Suppose be real numbers. Suppose that rthat r22 – c – c11r – cr – c22 = 0 has two distinct roots r = 0 has two distinct roots r11 and r and r22..Then the sequence {aThen the sequence {ann} is a solution of the } is a solution of the recurrence relation arecurrence relation ann = c = c11aan-1n-1 + c + c22aan-2n-2 if and only if if and only if aann = = 11rr11

nn + + 22rr22nn for n = 0, 1, 2, …, where for n = 0, 1, 2, …, where 11 and and 22

are constants.are constants.See pp. 321 and 322 for the proof.See pp. 321 and 322 for the proof.

Page 19: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 19

Solving Recurrence RelationsSolving Recurrence Relations

Example:Example: What is the solution of the recurrence What is the solution of the recurrence relation arelation ann = a = an-1n-1 + 2a + 2an-2n-2 with a with a00 = 2 and a = 2 and a11 = 7 ? = 7 ?

Solution:Solution: The characteristic equation of the The characteristic equation of the recurrence relation is rrecurrence relation is r22 – r – 2 = 0. – r – 2 = 0.Its roots are r = 2 and r = -1.Its roots are r = 2 and r = -1.Hence, the sequence {aHence, the sequence {ann} is a solution to the } is a solution to the recurrence relation if and only if:recurrence relation if and only if:aann = = 1122n n + + 22(-1)(-1)nn for some constants for some constants 1 1 and and 22..

Page 20: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 20

Solving Recurrence RelationsSolving Recurrence RelationsGiven the equation aGiven the equation ann = = 1122n n + + 22(-1)(-1)nn and the initial and the initial conditions aconditions a00 = 2 and a = 2 and a11 = 7, it follows that = 7, it follows thataa00 = 2 = = 2 = 1 1 + + 22

aa11 = 7 = = 7 = 112 + 2 + 2 2 (-1)(-1)

Solving these two equations gives usSolving these two equations gives us11 = 3 and = 3 and 22 = -1. = -1.

Therefore, the solution to the recurrence relation Therefore, the solution to the recurrence relation and initial conditions is the sequence {aand initial conditions is the sequence {ann} with} withaann = 3 = 322nn – (-1) – (-1)nn. .

Page 21: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 21

Solving Recurrence RelationsSolving Recurrence Relationsaann = r = rnn is a solution of the linear homogeneous is a solution of the linear homogeneous recurrence relationrecurrence relationaann = c = c11aan-1n-1 + c + c22aan-2n-2 + … + c + … + ckkaan-kn-k if and only ifif and only ifrrnn = c = c11rrn-1 n-1 + c+ c22rrn-2 n-2 + … + c+ … + ckkrrn-kn-k..Divide this equation by rDivide this equation by rn-kn-k and subtract the and subtract the right-hand side from the left:right-hand side from the left:rrkk - c - c11rrk-1 k-1 - c- c22rrk-2 k-2 - … - c- … - ck-1k-1r - cr - ckk = 0 = 0This is called the This is called the characteristic equationcharacteristic equation of of the recurrence relation.the recurrence relation.

Page 22: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 22

Solving Recurrence RelationsSolving Recurrence RelationsThe solutions of this equation are called the The solutions of this equation are called the characteristic rootscharacteristic roots of the recurrence relation. of the recurrence relation.Let us consider linear homogeneous recurrence Let us consider linear homogeneous recurrence relations of relations of degree twodegree two..Theorem:Theorem: Let c Let c11 and c and c22 be real numbers. Suppose be real numbers. Suppose that rthat r22 – c – c11r – cr – c22 = 0 has two distinct roots r = 0 has two distinct roots r11 and r and r22..Then the sequence {aThen the sequence {ann} is a solution of the } is a solution of the recurrence relation arecurrence relation ann = c = c11aan-1n-1 + c + c22aan-2n-2 if and only if if and only if aann = = 11rr11

nn + + 22rr22nn for n = 0, 1, 2, …, where for n = 0, 1, 2, …, where 11 and and 22

are constants.are constants.See pp. 321 and 322 for the proof.See pp. 321 and 322 for the proof.

Page 23: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 23

Solving Recurrence RelationsSolving Recurrence Relations

Example:Example: Give an explicit formula for the Give an explicit formula for the Fibonacci numbers.Fibonacci numbers.Solution:Solution: The Fibonacci numbers satisfy the The Fibonacci numbers satisfy the recurrence relation frecurrence relation fnn = f = fn-1n-1 + f + fn-2n-2 with initial with initial conditions fconditions f00 = 0 and f = 0 and f11 = 1. = 1.The characteristic equation is rThe characteristic equation is r22 – r – 1 = 0. – r – 1 = 0.Its roots areIts roots are

251,

251

21

rr

Page 24: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 24

Solving Recurrence RelationsSolving Recurrence RelationsTherefore, the Fibonacci numbers are given byTherefore, the Fibonacci numbers are given by

nn

nf

251

251

21

for some constants for some constants 11 and and 22..We can determine values for these constants so We can determine values for these constants so that the sequence meets the conditions fthat the sequence meets the conditions f00 = 0 = 0 and fand f11 = 1: = 1:

0210 f

12

512

51211

f

Page 25: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 25

Solving Recurrence RelationsSolving Recurrence RelationsThe unique solution to this system of two The unique solution to this system of two equations and two variables isequations and two variables is

51,

51

21

So finally we obtained an explicit formula for So finally we obtained an explicit formula for the Fibonacci numbers:the Fibonacci numbers:

nn

nf

251

51

251

51

Page 26: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 26

Solving Recurrence RelationsSolving Recurrence RelationsBut what happens if the characteristic equation has But what happens if the characteristic equation has only one root?only one root?How can we then match our equation with the initial How can we then match our equation with the initial conditions aconditions a00 and a and a1 1 ??Theorem:Theorem: Let c Let c11 and c and c22 be real numbers with c be real numbers with c22 0. Suppose that r0. Suppose that r22 – c – c11r – cr – c22 = 0 has only one root r = 0 has only one root r00. .

A sequence {aA sequence {ann} is a solution of the recurrence } is a solution of the recurrence relation arelation ann = c = c11aan-1n-1 + c + c22aan-2n-2 if and only if if and only if aann = = 11rr00

nn + + 22nrnr00nn, for n = 0, 1, 2, …, where , for n = 0, 1, 2, …, where 11 and and

22 are constants. are constants.

Page 27: Chapter 6 (.ppt file)

Fall 2002 CMSC 203 - Discrete Structures 27

Solving Recurrence RelationsSolving Recurrence RelationsExample:Example: What is the solution of the recurrence What is the solution of the recurrence relation arelation ann = 6a = 6an-1n-1 – 9a – 9an-2n-2 with a with a00 = 1 and a = 1 and a11 = 6? = 6?Solution:Solution: The only root of r The only root of r22 – 6r + 9 = 0 is r – 6r + 9 = 0 is r00 = 3. = 3.Hence, the solution to the recurrence relation isHence, the solution to the recurrence relation isaann = = 1133nn + + 22n3n3nn for some constants for some constants 11 and and 22..To match the initial condition, we needTo match the initial condition, we needaa00 = 1 = = 1 = 11aa11 = 6 = = 6 = 113 + 3 + 2233Solving these equations yields Solving these equations yields 11 = 1 and = 1 and 22 = 1. = 1.Consequently, the overall solution is given byConsequently, the overall solution is given byaann = 3 = 3nn + n3 + n3nn..