1 / 32

CHAPTER TWO RECURRENCE RELATION

CHAPTER TWO RECURRENCE RELATION. BY Dwee. Background. Computer programming Given a function to find faktorial n! in Pascal We can make this function in another way, which is defined by recalling itself (recursive function). f unction faktorial (n:integer): longint ; Var i:integer;

banyan
Download Presentation

CHAPTER TWO RECURRENCE RELATION

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CHAPTER TWORECURRENCE RELATION BY Dwee

  2. Background • Computer programming • Given a function to find faktorial n! in Pascal • We can make this function in another way, which is defined by recalling itself (recursive function) function faktorial(n:integer):longint; Var i:integer; Begin faktorial:=1; for i:=1 to n do faktorial:=faktorial*i; End;

  3. Background • Recursive function • This function is more simple but sometimes it use more memory than the function before • Some time we can solve a problem easily by recursive function than using iteration function faktorial(n:integer):longint; Begin if n=1 then faktorial:=1 else faktorial:=n*faktorial(n-1); End;

  4. Background • After this course, you should be able to • Solve a some simple kinds of recurrrence relation • Use forward and backward subtition to find the solution of recurrence relation • Make recurrence relation model from a problem • Solve 1st and 2nd order homogenous linear recurrence relation with constant coeficient • Solve 1st and 2nd order non-homogenous linear recurrence relation with constant coeficient

  5. INTRODUCTION • Let a geometric series: 5, 15, 45, 135, …. • If we write the terms as a1, a2, a3, …, an we have a2/a1=a3/a2=a4/a3=….=an/an-1=3 or we can write the relation between the terms in recurrence relation as an = 3 an-1, n  0 (*) • But recurrence relation (*) doesn’t define a unique geometric series, because 1,3,9, 27 ,…. also satisfy the relation. • To pinpoint the particular sequence described by an = 3 an-1, n  0, we need to know one of the terms of that sequence

  6. INTRODUCTION • Hence:, an = 3 an-1, n  0, a0=5 uniquely define sequence 5, 15, 45, ….

  7. Recurrence Relation • Recurence Relation : a relation that describe a function a(n), written as an, n 0, where an is depend on the the prior terms an-1, an-2, an-3, …, a1, a0. • Example: Fibonacci Series: 1, 1, 2, 3, 5, 8, …. By recurence relation it is given as a0= 1, a1=1, an=an-1+an-2 (n2)

  8. Recurrence Relation • Recurrence Relation consists of two parts • A set of initial or boundary condition • A rule or recurrence part • Example: Fibonacci series an=an-1+an-2 (recurrence part) with a0= 1, a1=1,(n2) (initial condition)

  9. Recurrence Relation • Solution of recurrence relation • General Solution • Iterative procedure computing • Forward subtitution • Backward subtitution • Example: • Find the general solution of recurrence relation a. an= 3an-1, a1= 2, n2 b. an = an-1 + n, a0=0, n1 c. an = 2an-1 + 1, a0=0, n1

  10. Recurrence Relation • Example: • Find a8 from this recurrence relation using Forward and Backward subtitution a0= 1, a1=1, an=an-1+an-2 (n2) • Find a6 from this recurrence relation using forward and backward subtitution with a1 =1, a2=1, n n3

  11. Modelling Problems to Recurrence Relation • A Bank pay 6% annual interest in savings, compounding the interest monthly. If Bonnie deposits $1000 on the first day on May, how much will this deposit b e worth a year later? Express the problem in the recurrence relation first. • Find a recurrence relation for the number of regions into which the plane is divided by n straight lines if every pair of lines intersect, but no three lines, meet the common point • Find a Recurrence Relation for the number of n digits binary sequences with no consecutive ones.

  12. Modelling Problems to Recurrence Relation • Recurrence Relation with more than one variable • Examples: Pascal Identity C(n,r) = C(n-1, r-1) + C(n-1,r) with boundary condition C(n,0)=1 and C(n,n)= 1. Use backward subtition to find C(5,4) by this recurrence relation! • Example: Find Recurrence relation for P(n,r) the number of r-permutation from {x1, x2, …, xn}!

  13. Linear Recurrence Relation with Constant Coefficient • General linear recurrence relation of degree k an + h1(n) an-1+ h2(n)an-2 + …+ hr(n)an-k=f(n) where h and f are functions and hr 0. If f(n) = 0 then the relation is called homogeneous, otherwise the relation is inhomogenous. And f is called inhomogenous part. If h’s are constant functions then the relation is called linear recurrence relation with constant coefficient.

  14. Linear Recurrence Relation with Constant Coefficient • A well defined linear recurrence relation of degree k consist of a recurrence relation part and k initial condition for k consecutive values  define one and only one function (solution) • Example : an – 5 an-1 + 6 an-2 = 0 is satisfied by an = C12n + C23n for any coonstant C1 and C2. Let initial condition are a0 = 2 and a1=5, we need a0 = 2 = C120 + C230  2 = C1 + C2 a1 = 5 = C121 + C231  5 = 2C1 + 3C2 this system has the solution C1=1 and C2 = 1. So the solution of the recurrence relation is an = 2n + 3n

  15. Linear Recurrence Relation with Constant Coefficient • Given a recurrence part of degree k, the strategy is to find a solution with k arbitrary constant C1, C2, …, Ck such that we can satisfy any set of k consecutive initial condition by solving a system of k simultaneous equation (one for each initial condition) in k unknowns (Ci) • Such a solution is called a general solution

  16. Homogenous Linear Recurrence Relation with Constant Coefficient : The Method of Characteristic Root • Superposition Principle: If g1(n) is a solution of an + c1 an-1+ c2an-2 + …+ ckan-k=f1(n) and if g2(n) is a solution of an + c1 an-1+ c2an-2 + …+ ckan-k=f2(n) then C1g1(n) +C2 g2(n) is a solution of an + c1 an-1+ c2an-2 + …+ ckan-k=C1 f1(n)+ C2 f2(n) for any constant C1 and C2

  17. Its follow immediately if g1 (n), g2(n), …, gk(n) are solutions of an + c1 an-1+ c2an-2 + …+ ckan-k=0 then so is C1g1 (n)+ C2g2(n)+ …+Ckgk(n) • How do we find different solution gi(n)? One of the choice is to look for solution in form rn for some number r

  18. Homogenous Linear Recurrence Relation with Constant Coefficient : The Method of Characteristic Root • Given Recurrence relation: an + c1 an-1+ c2an-2 + …+ ckan-k=0 • Let an = rn , subtituting to the recurrence relation yields rn + c1rn-1+ c2rn-2 + …+ ckrn-k=0 rn-k(rk + c1rk-1+ c2rk-2 + …+ ck)=0 rk + c1rk-1+ c2rk-2 + …+ ck=0 • The last equation is called by characteristic equation. Its roots are called characteristic roots. • Base on the characteristic roots, we have two case of the solutions • Case 1 : All the roots are distinct • Case 2 :There are some multiplicity roots

  19. Homogenous Linear Recurrence Relation with Constant Coefficient : The Method of Characteristic Root • Case 1: All of characteristic roots are distinct If r1, r2, …, rk is distinct characteristic root, so by using superposition principle, the general solution of the recurrence relation is an = C1r1n + C2r2n+…+Ckrkn • Example: Solve the recurrence relation 1) an + an-1 – 6 an-2 = 0, a0=1, a1=2, n2 2) an = an-1 + an-2, a0=0, a1=1, n2 (Fibonacci series) 3) an=2an-1+an-2-2an-3 , a0 =0, a1=1, a2=1, n3

  20. Homogenous Linear Recurrence Relation with Constant Coefficient : The Method of Characteristic Root • If the charactristic roots are complex numbers • Recall De Moivre’s Theorem: (cos + i sin )n = cos n+ i sin (n). If z = x + iy, we can write z = r (cos + i sin ) where r = sqrt(x2+ y2) and (y/x) = tan  then zn = (r (cos + i sin ) )n= rn(cos n+ i sin n). • Example: Solve the recurrence relation an = 2an-1-2an-2 , a0=1, a1=2, n2

  21. Homogenous Linear Recurrence Relation with Constant Coefficient : The Method of Characteristic Root • Case 2: The characteristic equation has multiplicity roots • Example: Solve the recurrence relation an = 4an-1-4an-2 , a0 =1, a1=3, n2

  22. If r is a characteristic root of multiplicity m, then it contributes m solution: rn, nrn, n2rn, …, nm-1rn. • Examples: Solve The recurrence relation a0=1, a1=1, a2=2, an = 4an-1-5an-2+2an-3

  23. Inhomogeneous Recurrence Relation • Towers of Hanoi. Consider n circular disks (having different diameters) with holes in their centers. These disks can be stacked on any of the pegs shown in Fig. 10.11. In the figure, n = 5 and the disks are stacked on peg 1 with no disk resting upon a smaller one. The objective is to transfer the disks one at a time so that we end up with the original stack on peg 3. Each of pegs 1, 2, and 3 may be used as a temporary location for any disk(s), but at no time are we allowed to have a larger disk on top of a smaller one on any peg. What is the minimum number of moves needed to do this for n disks?

  24. Inhomogeneous Linear Recurrence Relation with Constant Coefficient • Recurrence relation: an + c1 an-1+ c2an-2 + …+ ckan-k= f(n) with r consecutive initial conditions • Our strategy is the same as that used in the homogeneous case. • Find the general solution to the recurrene part, and use the initial condition to set up a system of simultaneous equation • By superposition principle: If anh is the solution of an + c1 an-1+ c2an-2 + …+ ckan-k= 0 and if anp is the solution of an + c1 an-1+ c2an-2 + …+ ckan-k= f(n) then anh + anp is also the solution of the recurence relation

  25. Inhomogeneous Linear Recurrence Relation with Constant Coefficient • anh is homogeneous part solution and anp is particular solution • How to find anh? Using characteristic equation • How to find anp? No general method, but some techniques are available for certain special case (method of undetermined coefficient). • Example: • Solve the recurrence relation: an- 3an-1=5 (7)n, a0=2, n1 • Solve the recurrence relation: an+3an-1=4n2-2n, a1=-4, n2 • Solve the recurrence relation: an- 4an-1+4an-2= 2n, a0=0 a1=1, n2

  26. Inhomogeneous Linear Recurrence Relation with Constant Coefficient • Solve the recurrence relation :an- 3an-1=5 (7)n, a0=2, n1 • Answer: • Homogenous part: an- 3an-1=0 Characteristic equation: r-3=0, charactristic root :r=3 Homogenous part solution: G(n)=c3n • Inhomogenous part: an- 3an-1=5(7)n We are “guessing” that the particular solution p(n)=A(7n) Subtituting p(n) into RR: A(7n)-3 A(7n-1)=5 (7n) 7n-1 (7A-3A)=7n-1(5.7) 4A = 35 A=35/4 • General solution: an = G(n)+p(n) = c 3n + 35/4 (7)n with a0 = 2, we get c= … so the solution is an = …..

  27. Inhomogeneous Linear Recurrence Relation with Constant Coefficient • Solve the recurrence relation: an+3an-1=4n2-2n, a1=-4, n2 • Answer: • Homogenous part: an+3an-1=0 Homogenous part solution: G(n)=c1(-3)n • Inhomogenous part: an+3an-1=4n2-2n Particular solution is polunomial of degree 2 or higher Guess that p(n) is polynomial of degree 2, p(n) = An2+Bn+C. Subtituting p(n) the RR: An2+Bn+C + 3(A(n-1)2+B(n-1)+C)= 4n2-2n 4An2+(4B-6A)n+(3A-3B+4C)=4n2-2n Solving the equation ,we have: A=1, B=1, C=0. The particular solution is p(n) = n2+n • General solution is an=G(n)+p(n)= c1(-3)n + n2+n Find the solution based on the initial condition

  28. Solve the recurrence relation an-an-1=n, a0=1, n1 • Answer: • Homogenous part: an-an-1= 0 Homogenous part splution part: anh = c(1)n=c • Inhomogenous part: an-an-1=n Because f(n) =n so the particular solution is polynomial of degree 1 or higher. Find the particular solution using guess • p(n) = An +B • p(n)= An2 +Bn +C which one give the solution? Why?

  29. Inhomogeneous Linear Recurrence Relation with Constant Coefficient • How to determine the degree of the polynomial guess? • The degree of anp is the degree of f(n) plus the multilicity of 1 in the characteristic equation • If 1 is not a root of characteristic equation, the degree of anp is the degree of f • Similarly if f(n) is of the form rn, then the particular solution will be Ankrn, where k is the multiplicity of r in the characteristic equation

  30. Inhomogeneous Linear Recurrence Relation with Constant Coefficient • Solve the recurrence relation an- 4an-1+4an-2= 2n, a0=0 a1=1, n2 • Answer: • Homogenous part: an- 4an-1+4an-2= 0 Characteristic equation: r2 – 4r + 4 = 0 Characteristic root: r = 2 (multiplicity of degree 2) Homogenous part solution: G(n) = …… • Inhomogeneous part: an- 4an-1+4an-2= 2n Particular solution is p(n)= … • The general solution is an = ….

  31. Given a linear nonhomogeneous recurrence relation (with constant coefficients) of the form C0an + C1an-1 + C2an-2 + • • • + Ckan-k = f(n) • Let Gn denote the homogeneous part of the solution an.

  32. EXERCISE. • a0=1, an-an-1= n2 • a0=1,a1=2, an-5an-1+6an-2 = 2n+1, n>=2 • a0=4, an-an-1=2n2-n-1, n>=1 • a0=1, a1=0, an-2an-1+an-2=2, n>=2 • a0=1, an+3an-1 =2n, n>=1 • a0=1, an+2an-1=2n-n2 , n>=1

More Related