Presentation is loading. Please wait.

Presentation is loading. Please wait.

Recurrence Relations.

Similar presentations


Presentation on theme: "Recurrence Relations."— Presentation transcript:

1 Recurrence Relations

2 Sequences A sequence is a discrete structure used to represent an ordered list. Def: A sequence is a function from a subset of the set of integers (usually the set (0, 1, 2, …} to a set S. We use the notation an to denote the image of an integer n. We call an a term of the sequence. We use the notation {an } to describe the sequence which stands for {a0, a1, a2, …., an}

3 Example : The sequence {an} where an = 1/n is 1, ½, 1/3, ¼, ……
Ex: A geometric progression is a sequence of the form a, ar, ar2, ar3, …., arn Def: A recurrence relation for the sequence {an } is an equation that expresses an in terms of one or more of the previous terms of the sequence. It is also called a difference equation Example: Consider the Geometric series { 1, 5, 25, 125, …..}. Its recurrence relation is an = 5an-1 with initial condition as a0=1. The equation an= 5n is called the solution of this recurrence relation

4 Example: Consider the Fibonacci series 1, 1, 2, 3, 5, 8, 13, 21, 34, ……
Its recurrence relation is an=an-1 + an-2 with the initial condition ( or boundary condition) as a0=1, a1=1 Example: The factorial series is described by the function an = n! with 0! =1. Give its equivalent rec. relation

5 Modeling with recurrence relations
Rabbits on an island :A young pair of rabbits(one male and one female) is placed on an island. A pair of rabbits does not breed until they are 2 months old. Thereafter each pair produces another pair (M/F) each month. Find a recurrence relation for the number of pairs of rabbits on the island after n months, assuming that no rabbits ever die.

6 Sol: Let fn be the no. of pairs of rabbits after n months
Sol: Let fn be the no. of pairs of rabbits after n months. Then f1 =1 and f2=1 since the sole pair on the island does not breed till it is 2 months old. Thereafter to find fn, we can add the no. of pair on the island the previous month i.e. fn-1 and the no. of newborn pairs, which equals fn-2 , since each newborn pair comes from a pair at least 2 months old. Consequently , the sequence {fn} satisfies the recurrence relation, fn = fn-1 + fn-2 for n>= 3 with the initial conditions f1 =1 and f2=1.

7 You may notice that the number of pairs of rabbits on the island after n months is nothing but the nth Fibonacci number The Tower of Hanoi  This popular puzzle called the tower of Hanoi consists of three pegs mounted on a board together with discs of varying sizes. Initially these discs are placed on the first peg in order of size, with the largest on the bottom. The rule of the puzzle allow discs to be moved one at a time from one peg to another as long as a disc is never placed on top of a smaller disc.

8 The goal of the puzzle is to have all the discs on the second peg in order of size, with the largest on the bottom. Can we set up a recurrence relation to calculate the no. of moves required to solve the puzzle for any given no. of discs n. Sol: Let Hn be no. of moves needed to solve the Tower of Hanoi puzzle with n discs. We begin with n discs on peg 1. we can transfer the top n-1 discs, following the rules of the puzzle, to peg 3 using Hn-1 moves.

9 We keep the largest disc fixed during these moves
We keep the largest disc fixed during these moves. Then we use one move to transfer the largest disc to the second peg. Now we can transfer the n-1 discs on peg 3 to peg 2 using Hn-1 additional moves, placing them on top of the largest disc which is already there. Hence Hn = Hn-1 +Hn-1+1 The initial condition is H1 =1, since one disc can be transferred from peg 1 to peg 2 in one move.

10

11 Solution of recurrence relation 
A function f(n) satisfying the given recurrence relation is called the solution of the recurrence relation. Example: Determine whether the sequence {an} is a solution of the recurrence relation an= 2an-1 – an-2, for n= 2,3,4,…. Where an= 2n for n>=0.   Sol: Given rec. relation is an= 2an-1 – an-2, for n= 2,3,4,…. Given solution is an= 2n  Hence an-1 = 2(n-1) and an-2 = 2(n-2) LHS = an = 2n RHS = an = 2.2(n-1) – 2(n-2) = 4n -2 -2n +2 = 2n , LHS = RHS Hence the function an = 2n is a solution of the given rec. relation

12 Example: Determine whether the sequence {an} is a solution of the recurrence relation an= 2an-1 – an-2, for n= 2,3,4,…. Where an= 2n for n>=0.  Sol: Given solution is an= 2n Hence an-1 = 2(n-1) and an-2 = 2(n-2) LHS = an = 2n RHS = an = 2.2(n-1) – 2(n-2) = (¾)2n Hence LHS ≠ RHS Hence the function an = 2n is not a solution of the given rec. relation

13 How to solve a recurrence relation
There are three important methods to solve a given rec. relation.  1) Backtracking method   This method banks upon identifying a pattern emerging out from the arrangement of terms. Once you get the pattern , you get the solution.  Example: Solve the recurrence relation an = an using backtracking method. a1 =2 Sol: We will start from an and move backwards towards a1 to find a pattern if any. To backtrack we keep on substituting the definition of an, an-1, an-2 until a recognizable pattern emerges

14 an = an = an = an x3 = an x3 = an x [ note the pattern] = ……. = an-r+r.3 Put r= n-1 = an-(n-1) + (n-1)x3 [ note the pattern] = a1 + 3(n-1) = (n-1) [ since a1 =2]   therefore an = 3n – 1 is the solution of the given rec. relation

15 Example: Solve the rec. relation bn =2bn-1 +1, b1=7 using BTM.
Sol: Given rec. relation is bn = 2bn-1 +1 = 2(2bn-2 +1) +1 = 4bn-2 +3 = 4(2bn-3 +1) +3 = 8bn [ =23bn ] = 8(2bn-4 +1) +7 = 16bn-4 +15 = 24bn = ………………. = 2n-1bn-(n-1) +2n-2 + 2n-3 + ……

16 = 7x 2n (2n-2 + 2n-3 + …… ) = 7x 2n n [ sum of a G.P. = (arn –a)/(r-1) ] =7x 2n n-1 -1 = 8x 2n-1 -1 = 23x 2n-1 -1 = 2n+2 -1

17 Example: Solve the recurrence relation to expressing the number of moves required to solve the Tower of Hanoi puzzle using BTM. Sol: From previous example, we get the rec. relation as Hn = 2Hn , H1 =1 Hn = 2(2Hn-2 +1) +1 = 22Hn = 23Hn = ……….

18 = ………. = 2n-1H1 + 2n-2 + 2n-3 + …. + 2 + 1 = 2n-1 + 2n-2 + 2n-3 + …
= ………. = 2n-1H1 + 2n-2 + 2n-3 + … = 2n-1 + 2n-2 + 2n-3 + … = 2n -1 n>=1 [using the formula for sum of a GP]

19 Example : Find a recurrence relation and give initial conditions for the number of bit strings of length n that do not have two consecutive 0s. Sol: Let an denote the number of bit strings of length n that do not have two consecutive 0s. To obtain a recurrence relation for {an}, note that by the sum rule, the number of bit strings of length n do not have two consecutive 0s equal the number of such bit strings ending with a 0 plus the number of such bit strings ending with a 1.

20 We will assume that n ≥ 3, so that the bit string has at least three bits.
The bit strings of length n ending with 1 that do not have two consecutive 0s are precisely the bit strings of length n-1 with no two consecutive 0s with a 1 added at the end. Consequently, there are an-1 such bit strings.

21 Bit strings of length n ending with a 0 that do not have two consecutive 0s must have 1 as their (n – 1)st bit; otherwise they would end up with a pair of 0s.it follows that the bit strings of length n ending with a 0 that have no two consecutive 0s are precisely the bit strings of length n – 2 with no two consecutive 0s with 10 added at the end. Consequently, there are an – 2 such bit strings. We conclude that, an = an – 1 + an – for n ≥ 3.

22 The initial conditions are a1 = 2, since both strings of length one, 0 and 1 do not have consecutive 0s, and a2 = 3, since the valid bit strings of length two are 01, 10 and 11. To obtain a5, we use the recurrence relation three times to find that a3 = a2 + a1 = = 5, a4 = a3 + a2 = = 8, a5 = a4 + a3 = = 13.

23 Lines in a plane Q: Set up a recurrence relation to find the maximum number of regions defined by n lines in a plane. Sol: Let Ln represent the maximum no. of regions defined by n lines in a plane. We can see that L0 = 1, L1 =2, L2 =4, L3 = 7

24 Now it is clear that nth lines adds n new regions to a plane provided that it is able to split n-1 old zones into two which is further possible only if it is able to intersect all the n-1 old lines at new intersection points. Since this can be easily shown to be possible (by drawing the newest line in way that it is not parallel to any of the existing lines and making it go through new intersection points.), we can set up the rec. relation as below Ln = Ln-1 + n, L0 = 1 The relation is easily solved using backtracking method. Ln = n(n+1)/2 + 1

25 Q. A computer system considers a string of decimal digits a valid codeword if it contains an even no. of 0 digits. Find a rec. relation to enumerate maximum no. of valid code words of length n. Sol: Let An represent max. no. of valid code words of length n. Then we note that A1 = 9, since out of 10 1-bit strings there is only one string namely “0” which is not a valid code word. A rec. relation for this sequence can be derived by considering how a valid n-digit string can be obtained from strings of n-1 digits.

26 There are only two ways to form a valid n-digit string from a valid/invalid string of n-1 digits.
by appending a digit other than zero to a valid string of length n-1 by appending a 0 digit to an invalid string of length n-1 First procedure can be done in 9 ways giving rise to 9An-1 valid strings of length n.

27 Second procedure can be done in only one way thereby giving rise to x valid strings of length n where x represents the no. of invalid strings of length n-1. X is easily obtained by subtracting the no. of valid strings of length n-1 which is An-1 from the total no. of strings possible out of 10 digits, which is 10n-1. Therefore x = 10n-1 – An-1 We have, An = 9An n-1 – An-1 = 8An n-1

28 2) Solving Homogeneous Linear Equations with constant coefficients
Def: A linear homogeneous recurrence relation of degree k with constant coefficients is a recurrence relation of the form An = c1an-1 + c2an-2 + … + ckan-k Where c1, c2, …., ck are real numbers, and ck ≠ 0 The recurrence relation is linear since the RHS is a sum of multiples of the previous terms of the sequence. An = c1an-1 + c2a2n-2 is not linear.

29 It is homogeneous since no terms occur that are not multiples of the ajs. The relation Hn=2Hn-1 +1 is not homogeneous. The coefficients of the terms are all constants. The relation an = nan-1 does not have constant coefficients. The relation an = 2an-1 has degree 1. The relation an = 2an-1 + 3an-2 has degree 2. The relation an = 2an-5 has degree 5.

30 Characteristic Equation and roots 
If an = c1an-1 + c2an-2 be a given recurrence relation then the equation m2 –c1m –c2 = 0 is called its characteristic equation. Solutions of this equation are called the characteristic roots of the recurrence relation. These roots can be used to give a formula for all the solutions of the given recurrence relation as shown below.

31 Case 1: If there are two distinct roots- m1 and m2, the solution of the recurrence relation is given by an = Am1n + Bm2n where A and B are constants. Example: What is the solution of the recurrence relation an = an-1 + 2an-2 with a0 = 2 and a1 = 7 ? Sol: The characteristic equation is m2 –m –2 = 0. Hence (m+1)(m-2)=0  m=-1 or m=2 Hence the roots are m1= -1 and m2= 2 The general solution is the sequence {an} where an = Am1n + Bm2n Or an = A(-1)n + B(2)n

32 Now, We use the initial conditions to find the constants A and B. Substituting the values a0 = 2 and a1 = 7 in the above equation, we get a0 = A(-1)0 + B(2)0 or 2 = A + B ) and, a1 = A(-1)1 + B(2)1

33 or, 7 = -A + 2B ) Adding 1) and 2) We get 3B = 9 or B=3 ,  A= -1 Hence the solution of the given recurrence relation is the sequence {an} where an = -(-1)n + 3(2)n

34 Example: Solve the recurrence relation for the fibonacci series.
Sol: The rec. relation for fib. Series is given by an = an-1 + an-2 with the initial conditions as a0 = 1 and a1 = 1 The characteristic equation is m2 –m –1 = 0. Hence (m+1)(m-2)=0  m=-1 or m=2 Hence the roots are m1= (1+√5)/2 and m2= (1-√5)/2 { roots of a quadratic equation am2 +bm +c = 0 are (-b +- √(b2 –4ac))/2a }

35 The general solution is the sequence {an} where an = Am1n + Bm2n Or
The general solution is the sequence {an} where an = Am1n + Bm2n Or an = A((1+√5)/2)n + B((1-√5)/2)n Now, We use the initial conditions to find the constants A and B. Substituting the values a0 = 1 and a1 = 1 in the above equation, we get 1 = A + B ) and, 1 = A(1+√5)/2 + B(1-√5)/ ) Solving 1) and 2) for A and B, We get,

36 A = √ and B = √5 √ √ Hence the solution of the given recurrence relation is the sequence {an} where an = (1 + √5)n (1- √5)n+1 √5 ( ) √5 ( )

37 Case2 : If an = c1an-1 + c2an-2 + c3an-3 be a given recurrence relation then the equation m3 –c1m2 –c2m –c3 = 0 is its characteristic equation. If there are 3 distinct roots m1, m2 and m3, then the general solution is given by an = Am1n+Bm2n+Cm3n where A, B and C are constants. Example: Find the solution to the recurrence relation an = 6an-1 -11an-2 + 6an-3 with the initial conditions as a0 =2, a1=5, a2= 15

38 The characteristic equation is m3 –6m2 +11m–6 = 0
Hence the roots are m1 = 1, m2 = 2, m3 = 3 General solution of the recurrence relation is given by an = Am1n+Bm2n+Cm3n where A, B and C are constants. Hence an = A(1)n+B(2)n+C(3)n

39 Using the initial conditions, we can form three simultaneous
equations as below. 2 = A + B + C ) 5= A + 2B +3C ) 15 =A + 4B + 9C ) Solving the above equations for A,B and C we get A=1, B=-1 and C=2 Hence the solution of the recurrence relation is given by the sequence {an} where an = 1-2n+2(3)n

40 Case 3: If there is only one root say m, for the characteristic equation m2 –c1m –c2 = 0 the solution of the recurrence relation is given by an = (A+nB)mn where A and B are constants. Example: What is the solution of the recurrence relation an = 6an-1 - 9an-2 with a0 = 1 and a1 = 6 ? Sol: The characteristic equation is m2 –6m +9 = 0. Hence (m-3)(m-3)=0  m=3 or m=3

41 Since there is only one root, the general solution is the sequence {an} where an = Amn + nBmn
Or an = A3n + nB3n for some constants A and B Now, We use the initial conditions to find the constants A and B. Substituting the values a0 = 1 and a1 = 6 in the above equation, we get a0 = A(3)0 + B.0.(3)0 or A= )

42 and, a1 = A(3)1 + B(3)1 or, 3A + 3B = ) From 1) and 2) We get A=1 and B=1 Hence the solution of the given recurrence relation is the sequence {an} where an = 3n + n3n for n >=0

43 Case 4: If an = c1an-1 + c2an-2 + c3an-3 be a given recurrence relation then the equation m3 –c1m2 –c2m –c3 = 0 is its characteristic equation. If there is one single root of multiplicity 3, then the general solution is given by an = (A+Bn+Cn2)rn where A, B and C are constants. Example: Find the solution to the recurrence relation an = -3an-1 -3an-2 - an-3 with the initial conditions as a0 =-1, a1=-2, a2= -1

44 Sol: The characteristic equation is m3 +3m2 +3m+1 = 0
Hence there is a single root m= -1 of multiplicity 3. General solution of the recurrence relation is given by the sequence {an} where an = Am1n+nBm2n+n2Cm3n where A, B and C are constants. Hence an = A(-1)n+nB(-1)n+n2C(-1)n

45 Using the initial conditions, we can form three simultaneous
equations as below. 1 = A ) -2 = -A -B -C ) -1 =A + 2B + 4C ) Solving the above equations for A,B and C we get A=1, B=3 and C=-2 Hence the solution of the recurrence relation is given by the sequence {an} where an =(1 +3n -2n2)(-1)n

46 Case 5: If m3 –c1m2 –c2m –c3 = 0 is characteristic equation and if two roots are equal say m and one distinct say r, then the general solution is given by an = (A+Bn)mn +Crn where A, B and C are constants.

47 Solve the recurrence relation an = -6an-1 - 12an-2 - 8an-3
With the initial conditions a0 =1, a1=-2, a2= 8

48 3) Solving Non-homogeneous recurrence relations with constant coefficients
A given recurrence equation can be arranged in standard form as : An + c1An-1+ c2An-2 +c3An-3 = RHS (1) Where c1,c2,c3 are constant coefficients and RHS has one of the following forms.

49

50 In the rec. equation (1), assigning RHS =0, we get
An + c1An-1+ c2An-2 +c3An-3 = (2) This equation (2) gives us the associated homogeneous equation for the given rec. equation which can be solved using the technique described earlier. The total solution of the rec. equation is found by adding the two parts, the homogeneous part which depends only on what in on the LHS, and the particular part which depends only on what is there on the RHS. This requires a guess-work as shown in the table.

51 There are four steps to the total solution.
Step 1: Find the solution to the homogeneous part by setting RHS to 0. Your answer will contain one or more undermined constants whose value can not be determined until step 4. If the RHS is already 0, skip the next two steps and go directly to step 4. Step 2: Find the particular solution by guessing a form similar to the RHS using the following table given below . This step neither produces any additional undetermined constants nor does it eliminate those from step 1.

52 Form Examples Guessed Particular Solution Homogeneous None A constant -3, 42, 11/2 An = C , a constant Linear expression 2n +5, -n An = Cn + D Gen linear expr Quadratic Expression 3n2 +5, n2-n+3 An = Cn2 + Dn +E Gen. Quad. expr Constant X Expo. Expr. 42 x 4n Cx4n gen constant X same expo. Expr Linear expr x Expo. Expr (2n +5) x 4n An = (Cn +D)x 4n Gen linear exp X same expon expression Quadr expr x Exp Expr (2n2 +5) X(4n) An = (Cn2 + Dn +E)x 4n Gen. Quad. expr X same expo. Expr

53 Step 3 :Combine the homogeneous and particular solutions Step 4: Use initial conditions to eliminate the undetermined constants from step 1.

54 Example: Find the solution of the recurrence relation an = 4an with a1 =4 as initial condition. Sol: The given rec. relation is an = 4an (1) Its standard form is an - 4an-1 = 1

55 Step 1: To find the homogenous solution:
 Its associated homogeneous equation is, an - 4an-1 = (3) The characteristic equation is, m – 4 = (4) hence m = 4 The homogeneous solution is anh) = C (4)n where C is a constant

56 Step 2: To find the particular solution:
We observe the RHS of equation (1), Since it is a constant,1, we make a guess for the particular solution as below: an(p) = D where D is a constant (5) Substituting the value of an in eq (1), we get D –4D =1 Hence D = - 1/3 Thus, an(p) = -1/3

57 Step 3: Combining the two parts, we get the total solution as:
An= an(h) + an(p) = C (4)n -1/ (6) where C is a constant

58 Step 4: using the initial conditions to find the value of C:
By substituting the value of a1 in eq (6), we get 4 = Cx 41 – 1/ (7) hence C = 13/12 substituting the value of C in eq (6), we get the total solution of the given recurrence relation as the sequence {an} where an= (13/12) (4)n -1/3 Ans.

59 Example: Solve the difference equation an = -2an-1 +n +3 with the boundary condition as
Sol: The given difference equation is an = -2an-1 +n (1) Its standard form is an + 2an-1 = n (2)

60 Step 1: To find the homogenous solution:
Its associated homogeneous equation is, an + 2an-1 = (3) The characteristic equation is, m +2 = 0 hence m = -2 The homogeneous solution is anh) = C (-2)n (4) where C is a constant

61 Step 2: To find the particular solution:
 We observe the RHS of equation (1), Since it is a linear expression (n+3) , we make a guess for the particular solution as below: an(p) = Bn + D (5) where B and D are constants Substituting the value of an and an-1 in eq (2), we get Bn + D + 2[ B(n-1) + D ] = n+3

62 Hence, (3B)n + (3D – 2B) = n (6) Comparing the coefficients of n and the constant terms on LHS and RHS of eq (6), we get 3B =1 and 3D- 2B = 3 which gives B =1/3 and D = 11/9 Substituting values of B and D in eq(5), we get an(p) = n/ / (7)

63 Step 3: Combining the two parts using eq(4) and eq(7) , we get the total solution as:
An= an(h) + an(p) = C (-2)n +n/3 +11/ (6) where C is a constant

64 Step 4: using the initial conditions to find the value of C:
By substituting the value of a0 in eq (6), we get 3 = Cx (-2)0 + 0/3 +11/ (7) hence C = 16/9 substituting the value of C in eq (7), we get the total solution of the given recurrence relation as the sequence {an} where an= (16/9) (-2)n +n/3 +11/9 Ans.

65 1) Solve the recurrence relation an = -6an-1 - 12an-2 - 8an-3
With the initial conditions a0 =1, a1=-2, a2= 8 2)Use the method of homogeneous solution and particular solution to solve 3an = 5an-1 -2an-2 +n with initial conditions as a0=-1 and a1 =1.

66 For the case that base of the exponential term is a characteristic root of multiplicity (k), when f(n) is of the form (B0nr + B1nr-1 + … + Br-1n + Br) mn The Corresponding solution is of the form nk(A0nr + A1nr-1 + … + Ar-1n + Ar) mn Example 1. Find the particular solution of an-2an-1=3x2n Solution: Step1. Given recurrence relation is an-2an-1 = 3x2n ……………………(1) Hence the characteristic equation is m–2= ⇒ m = 2, hence anh) = A (2)n where A is a constant.

67 Step 2: To find the particular solution:
In RHS 2 is a characteristic root (of multiplicity 1) . Hence the general form of the particular solution is Bnx2n Hence anp = Bnx2n Hence an = Bnx2n and an-1 = B(n-1) x 2n-1. Substitute these values in equation (1), we get Bnx2n - B(n-1) x 2n-1 = 3x2n Solving this we get B = 3. Hence anp = 3nx2n

68 Generating Functions Def: Given a sequence a = a0, a1, a2, ….., an, ……. Of real numbers, the summation g(x) = a0 + a1x + a2x2 + ….+ anxn + …….. is called the generating function of the sequence. Hence g(x) = ∑ akxk k=0 Example: What is the generating function for the series 1,1,1,1,1,1 ? Sol: The generating function g(x) = 1 + x + x2 + x3 + x4 + x5 Which is a geometric series with a=1, r=x and n=5 Hence g(x) = (x6-1) / (x-1)

69 Example: What is the generating function for the sequence {ak} where ak = C(m,k) for k=0,1,2,…..,m for any positive integer m ? Sol: Let g(x) be the generating function for this series. Then, G(x) = C(m,0) + C(m,1) x + C(m,2) x2 + …….. + C(m, m) xm = (1 + x) n by Binomial theorem The Binomial Theorem: Let x and y be variables and let n be a nonnegative integer. Then n (x+y)n =  ( n ) xn-j yj j= j = (n) xn + (n)xn-1y +(n)xn-2y2 + ….. + (n )xyn-1 + (n) yn n n

70 Some useful generating functions like these are listed below
Series ak G(x) 1 + C(n,1)x +C(n,2)x2 + ….. + xn C(n,k) (1 + x )n 1 + C(n,1)ax +C(n,2)a2 x2 + ….. + an xn C(n,k)ak (1+ax)n 1 + x + x2 +……..+ xn 1 (1-xn+1)/(1-x) 1 + x + x2 +…….. 1/(1-x) 1 + ax + a2 x2 +…….. 1/(1-ax)

71 Example: Use generating function to solve the recurrence relation an = 3an-1 for n = 1,2,3,… and initial condition a0=2. Sol: Let G(x) be the required generating function. Then G(x) = ∑ anxn (1) n=0 The given rec. relations is an = 3an (2) Multiplying (2) with xn on both sides, an xn = 3an-1 xn (2)

72 Taking summation from 1 to infinity on both sides,
∞ ∞ ∑ anxn = ∑ 3an-1xn n= n=1 ∞ ∞ ∑ anxn -a0 = 3x ∑ an-1xn-1 n= n=1 substituting values of G(x) and a0 on the LHS and m=n-1 on RHS G(x) -2 = 3x ∑ amxm m=0

73 again substituting value of G(x) on the RHS
G(x) -2 = 3x G(x) Hence G(x) = 2/(1-3x) Using a formula from the table, ∞ ∞ G(x) = 2/(1-3x) = 2 ∑3k xk = ∑ (2.3k )xk (6) k= k=0 but we know from eq(1), G(x) = ∑ akxk (1) k=0 comparing eq(1) and eq(6), we get ak= 2.3k Answer

74 Example: Use generating function to solve the recurrence relation an = 3an for n >= 1 and initial condition a0=2. Sol: Let G(x) be the required generating function. Then G(x) = ∑ anxn (1) n=0 = a0 + ∑ anxn (1) n=1 The given rec. relations is an = 3an (2) for n>=1

75 Multiplying (2) with xn on both sides,
an xn = 3an-1 xn + 2 xn (3) Taking summation from 1 to infinity on both sides, ∞ ∞ ∞ ∑ anxn = ∑ 3an-1xn + ∑ 2xn n= n= n=1 ∞ ∞ ∞ ∑ anxn -a0 = 3x ∑ an-1xn ∑ xn n= n= n=1

76 substituting values of G(x) and a0 on the LHS
and m=n-1 on RHS G(x) -2 = 3x ∑ amxm x/ (1-x) m=0 again substituting value of G(x) on the RHS G(x) -2 = 3x G(x) x/ (1-x) (1-3x) G(x) = x/ (1-x)

77 Hence G(x) = 2/[(1-x)(1-3x)]
= 3/(1-3x) - 1/(1-x) ∞ ∞ = 3 ∑ 3k xk - ∑ xk k= k=0 ∞ ∞ = ∑ 3k+1 xk ∑ xk k= k=0 = ∑ (3k+1-1) xk k=0

78 but we know from eq(1), G(x) = ∑ akxk (1) k=0 comparing eq(1) and eq(6), we get ak= 3k+1 – for n>=1

79 Example: Suppose a valid code word is a n digit decimal integer containing an even no. of zeros. Let An denote the no. of valid code words of length n. Set up a recurrence relation to find An. Solve the re. relation using generating functions. Sol: First we recognize that a valid n-digit code word can be formed by either appending a non-zero digit to any valid n-1 digit code word or appending a zero to any invalid code word of length n-1. Therefore a n = 9x + y (1) Where x is the no. of valid code words of length n-1 and y is the no. of invalid code words of length n-1.

80 Clearly, x = an-1 And y = 10n-1 - an-1 Substituting the values of x and y in eq (1) we get the required recurrence relation as an = 8an n-1 with a0 = 1 Now to solve the rec relation using generating functions, Sol: Let G(x) be the required generating function. Then G(x) = ∑ anxn (1) n=0 The given rec. relations is an = 8an n-1 with a0 = 1

81 Multiplying with an on both sides,
an xn = 8an-1 xn + 10n-1 xn (3) Taking summation from 1 to infinity on both sides, ∞ ∞ ∑ anxn = ∑ 8an-1xn ∑ 10n xn n= n= n=1 ∞ ∞ ∞ ∑ anxn - 1 = 8x ∑ an-1xn (1/10) ∑ (10x)n n= n= n=1 substituting values of G(x) and a0 on the LHS and m=n-1 on RHS G(x) -1 = 8x ∑ amxm + (1/10) [10x/ (1-10x)]

82 again substituting value of G(x) on the RHS
G(x) -1 = 8x G(x) + (1/10) [10x/ (1-10x)] (1-8x) G(x) = (1/10) [10x/ (1-10x)] Hence G(x) = (1-9x)/[(1-10x)(1-8x)] = (1/2)[1/(1-10x)] - (1/2)[1/(1-8x)] ∞ ∞ = 1/2 ∑10k xk - (1/2) ∑ 8k xk k= k=0

83 = ∑(1/2)(10k + 8k) xk k=0 but we know from eq(1), G(x) = ∑ akxk (1) comparing eq(1) and eq(6), we get ak= (1/2)(10k + 8k) for n>=0

84 Finite Differences Finite differences of sequences are of two types- forward and backward. Forward Difference Def: For a real numbers sequence {an}, the forward difference of the sequence is defined as below. First order forward difference is ∆an = an+1 – an Second order forward difference is ∆2an = ∆an+1 -∆an kth order forward difference is ∆k an = ∆k-1 an+1 -∆k-1 an

85 Example: Find ∆an where 1) an =3
2) an = 4n ) an= n2 +n +1 Sol: 1) ∆an = an+1 – an = 3- 3 =0 2)Given an= 4n+7 an+1 = 4n and an+1 =4(n+1) +7 ∆an = an+1 – an = [4(n+1)+7] - (4n+7) = 4 3) given an = n2 + n +1 an+1 = (n+1)2 +(n+1) +1 = n2 + 3n + 3 ∆an = an+1 – an = n2 + 3n + 3 –(n2 + n +1) = 2n +2

86 Example: Let an= 3n2 +n +2, find ∆k an where k equals
(i) (ii) (iii) 4 Sol: Given an= 3n2 +n +2 an+1= 3(n+1)2 +(n+1) +2 ∆an = an+1 – an = [3(n+1)2 +(n+1) +2] – (3n2 +n +2) = 6n +4 ∆an+1 = 6(n+1) +4

87 (i) ∆2an = ∆an+1 -∆an = 6(n+1)+4 – (6n+4) = 6
(ii) ∆3an = ∆2 an+1 -∆2 an ∆2an =6 therefore ∆2an+1 =6 ∆3an = 6-6 =0 (iii) ∆4an = =0

88 Example: Let an = {0 0<=n <=2
Find ∆an. Sol: a0 =0 , a1 =0 and a2 =0 hence ∆a0 = a1-a0 =0 ∆a1 = a2-a1 =0 now a3 = hence ∆a2 = a3-a2 = = = 1/8 +3 = 25/8

89 for n>=3 an = 2-n +3 and an+1 =2-(n+1) +3 Hence ∆an =2-(n+1) +3- (2-n +3) = -2-(n+1) Thus, { <=n<=1 ∆an = { 25/ n=2 { -2-(n+1) n >= 3

90 Backward Differences Def: For a real numbers sequence {an}, the forward difference of the sequence is defined as below. First order backward difference is ▼an = an – an-1 Second order backward difference is ▼2an = ▼an –▼an-1 kth order backward difference is ▼k an = ▼k-1 an –▼k-1 an-1 Assignment : Use generating functions to solve the recurrence relation an = 3 an for n>=1, a0 =2 an = { <=n <=2 { 2-n n>=3 Find ▼an.


Download ppt "Recurrence Relations."

Similar presentations


Ads by Google