390 likes | 408 Views
Agenda. Lecture Content: Recurrence Relations Solving Recurrence Relations Iteration Linear homogenous recurrence relation of order k with constant coefficients Exercise. Recurrence Relations. Recurrence Relations. Relates the n- th element of a sequence to its predecessors .
E N D
Agenda • Lecture Content: • Recurrence Relations • Solving Recurrence Relations • Iteration • Linear homogenous recurrence relation of order k with constant coefficients • Exercise
Recurrence Relations • Relates the n-th element of a sequence to its predecessors. • Example: an = 9 * an-1 • Closely related to recursive algorithms. • Suited for analysis of algorithm
Recurrence Relations • Generate a sequence : • Start with 5 • Given any term, add 3 to get the next term • 5, 8, 11, 14, … • Sequence {an} = a0, a1, …, an-1, an • a0= 5 initial condition • an = an-1 + 3 , n ≥ 1 recurrence relation
Recurrence Relations for the sequence {an} • is an equation that expresses an in 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 {an} is called a solution of a recurrence relation if its terms an satisfy the recurrence relation.
Motivation One of the main reason for using recurrence relation is that sometimes it is easier to determine the n-thterm of a sequence in terms of its predecessors than it is to find an explicit formula for the n-th term in terms of n.
Example • Let {an} be a sequence that satisfies the recurrence relation an = an-1 – an-2 for n = 2, 3, 4, … and suppose that a0 = 3 and a1 = 5. What are a2 and a3? • a2 = a1 – a0 = 5 – 3 = 2 • a3 = a2 – a1 = 2 – 5 = -3 • Also a4, a5, …
Exercises • Find the first six terms of the sequence defined by the following recurrence relations: • an= an-1 + an-3 • a0 = 1, a1 = 2, a2 = 0 • an= n. an-1 + (an-2)2 • a0 = -1, a1 = 0
Example • Find the recurrence relation of: • {an} = (0, 1, 2, 3, …) • {an} = (5, 10, 15, 20, …) • Find the first three terms of the sequence defined by the following recurrence relations: • an = 3 * an-1 – an-2 a0 = 3 and a1 = 5 • an = an-1 – an-2 + an-3 a0= 3, a1 = 5 and a2 = 5
Modelling with Recurrence Relations (1) • The number of bacteria in a colony doubles every hour. If a colony begins with five bacteria, how many will be present in n hours? • a0 = 5 • a1 = 10 • a2 = 20 • … • The number of bacteria at the end of n hours: an = 2 * an-1
Modelling with Recurrence Relations (2) • Suppose that a person deposits $ 10,000 in a saving account at a bank yielding 11% per year with interest compounded annually. How much will be in the account after 30 years? • Pn : the amount in the account after n years • Pn = Pn-1 + 0.11 Pn-1 = 1.11 Pn-1 • P0 = 10,000 • P1 = 1.11 P0 • P2 = 1.11 P1 = 1.11 * 1.11 P0 = (1.11)2 P0 • Pn = (1.11)n P0 • Pn = (1.11)n P0 • Deriving explicit formula from the recurrence relation and its initial condition (Section 7.2)
Converting to a Recursive Algorithm • A recursive function is a function that invokes itself. • A recursive algorithm is an algorithm that contains a recursive function • Input: n, the number of years • Output: the amount of money at the end of n years • compound_interest (n){ • if (n == 0) • return 10,000 • return 1.11 * compound_interest (n-1) • }
Modeling with Recurrence Relation (3) • A young pair of rabbits is placed on an island. A pair of rabbit does not breed until they are 2 months old. After they are 2 months old, each pair of rabbits produces another pair each month. Find a recurrence relation for the number of pairs of rabbit on the island after n months, assuming that no rabbits ever die. • fn : the number of pairs of rabbits after n months
Modeling with Recurrence Relation (3) Month reproducing pairs young pairs total pairs 1 0 1 1 2 0 1 1 3 1 1 2 4 1 2 3 5 2 3 5 6 3 5 8
Modeling with Recurrence Relation (3) • fn : the number of pairs of rabbits after n months • f1 = 1 • f2 = 1 • f3 = 2 • fn = the number on the island for the previous month + the number of newborn pairs • fn = fn-1 + fn-2 • Fibonacci Numbers
Modelling with Recurrence Relation (4) • Find a recurrence relation and give initial conditions for the number of bit strings of length nthat do not have two consecutives 0s. • an : the number of bit strings of length n that do not have two consecutive 0s.
1 0 1 1 0 1 1 0 1 0 1 1 1 0 1 0 0 1 The Tree Diagrams How many bit strings of length four do not have two consecutive 0s? bit ke-1 bit ke-2 bit ke-3 bit ke-4 There are eight bit strings
Modelling with Recurrence Relation (4) • an = an-1 + an-2 for n ≥ 3 • a1 = 2 0, 1 • a2 = 3 (01, 10, 11) • a3 = 5 (011, 010, 101, 110, 111) • a4 = 8
Solving Recurrence Relations • Given recurrence relations with sequence: a0 , a1 , … • Find an explicit formula for the general term: an • Two methods: • Iteration • Recurrence relations with constant coefficients
Iteration Steps: • Use the recurrence relation to write the n-th term anin terms of certain of its predecessors an-1, …, a0 • Use the recurrence relation to replace each of an-1, … by certain of their predecessors. • Continue until an explicit formula is obtained.
Iteration: Example 1 an = an-1 + 3 n ≥ 1 a0= 5 Solution: • an-1 = an-2 + 3 • an = an-1 + 3 = (an-2 + 3) + 3 = an-2 + 2.3 = (an-3 + 3) +2.3 = an-3 + 3.3 = an-k + k.3 … k = n = a0 + n . 3 = 5 + n . 3
Iteration: Example 2(1) • The number of bacteria in a colony doubles every hour. If a colony begins with five bacteria, how many will be present in n hours? • a0 = 5 • a1 = 10 • a2 = 20 • … • The number of bacteria at the end of n hours: an = 2 * an-1
Iteration: Example 2(2) an = 2 * an-1 = 2 * (2 * an-2 ) = 2 * 2 ( an-2 ) = 2 * 2 * (2 * an-3 ) = 23 ( an-3 ) … = 2n * a0 = 2n * 5
Iteration: Example 3 • The deer population is 1000 at time n = 0 • The increase from time n-1 to time n is 10 percent. • Find the recurrence relation, initial condition and solve the recurrence relation at time n • a0 = 1000 • an = 1.1 * an-1 • an = 1.1 * (1.1 * an-2) = 1.12 * an-2 • an = 1.1n * a0 • an = 1.1n * 1000
Definition • A linear homogeneous recurrence relation of order k with constant coefficients is a recurrence relation of the form: an = c1an–1+ c2an–2+ … + ckan–k , ck≠ 0 • Example: • Sn= 2Sn–1 • fn= fn–1 + fn–2
Not linear homogenous recurrence relations • Example: • an = 3an–1an–2 • an – an–1 = 2n • an = 3nan–1 Why?
Solving Recurrence Relations • Example: • Solve the linear homogeneous recurrence relations with constant coefficients an= 5an–1 – 6an–2 a0 = 7, a1= 16 • Solution: • Often in mathematics, when trying to solve a more difficult instance of some problem, we begin with an expression that solved a simpler version.
Solving Recurrence Relations • For the first-order recurrence relation, the solution was of the form Vn= tn; thus for our first attempt at finding a solution of the second-order recurrence relation, we will search for a solution of the form Vn= tn. • If Vn= tnis to solve the recurrence relation, we must have Vn= 5Vn–1–6Vn–2 or tn= 5tn–1 – 6tn–2 or tn– 5tn–1+ 6tn–2 = 0. Dividing by tn–2, we obtain the equivalent equation t2 – 5t1 + 6 = 0. Solving this, we find the solutions t= 2, t= 3. Characteristic polynomial Characteristic roots
Solving Recurrence Relations • We thus have two solutions, Sn= 2n and Tn= 3n. • We can verify that if S and T are solutions of the preceding recurrence relation, then bS+ dT, where b and d are any numbers, is also a solution of that relation. In our case, if we define the sequence U by the equation Un = bSn+ dTn= b2n + d3n, • U is a solution of the given relation.
Solving Recurrence Relations • To satisfy the initial conditions, we must have: 7 = U0 = b20 + d30= b + d, 16 = U1= b21+ d31= 2b + 3d. Solving these equations for b and d, we obtain b = 5, d = 2. • Therefore, the sequence U defined by Un= 5∙2n + 2∙3nsatisfies the recurrence relation and the initial conditions. • We conclude that an= Un= 5∙2n+ 2∙3n, for n = 0, 1, ….
Theorem • Let an = c1an–1+ c2an–2 be a second-order, linear homogeneous recurrence relation with constant coefficients. • If S and T are solutions of the recurrence relation, then U = bS+ dTis also a solution of the relation. • If r is a root of t2–c1t–c2= 0, then the sequence rn, n = 0, 1, …, is a solution of the recurrence relation. • If a is the sequence defined by the recurrence relation, a0 = C0, a1= C1, and r1 and r2 are roots of the preceding equation with r1≠ r2, then there exist constants b and d such that an= br1n + dr2n, n = 0, 1, ….
Example (1) • More Population Growth • Assume that the deer population of Rustic County is 200 at time n = 0 and 220 at time n = 1 and that the increase from time n–1 to time n is twice the increase from time n–2 to time n–1. • Write a recurrence relation and an initial condition that define the deer population at time n and then solve the recurrence relation.
Example (1) • Solution: • Let dndenote the deer population at time n. d0 = 200, d1 = 220 dn– dn-1= 2(dn-1 – dn-2) dn= 3dn-1 – 2dn-2 • Solving t2 – 3t + 2 = 0, we have roots 1 and 2. Then the sequence d is of the form dn= b∙1n + c∙2n = b + c2n. • To meet the initial conditions, we must have 200 = d0= b + c, 220 = d1= b + 2c. Solving for b and c, we find b= 180, and c= 20. • Thus, dnis given by dn= 180 + 20∙2n.
Example (2) • Find an explicit formula for the Fibonacci sequence: fn– fn–1 – fn–2= 0, n≥ 3 f1 = 1, f2 = 1 • Solution: • We begin by using the quadratic formula to solve t2 –t – 1 = 0. The solutions are t = (1 ±√5)/2. Thus the solution is of the form fn= b((1+√5)/2)n + c((1–√5)/2)n. • To satisfy the initial conditions, we must have b((1+√5)/2) + c((1–√5)/2)= 1, b((1+√5)/2)2+ c((1–√5)/2)2= 1. Solving these equations for b and d, we obtain b = 1/√5, d = -1/√5. • •Therefore, fn= 1/√5∙((1+√5)/2)n– 1/√5((1–√5)/2)n.
Theorem • Let an = c1an–1 + c2an–2 be a second-order, linear homogeneous recurrence relation with constant coefficients. • Let a be the sequence satisfying the relation and a0 = C0, a1= C1. • If both roots of t2 – c1t – c2 = 0 are equal to r, then there exist constants b and d such that an = brn+ dnrn, n = 0, 1, ….
Example • Solve the recurrence relation dn= 4(dn-1 – dn-2) subject to the initial conditions d0= 1 = d1. • According to the theorem, Sn= rnis a solution, where r is a solution of t2 – 4t + 4 = 0. Thus we obtain the solution Sn= 2n. • Since 2 is the only solution of the equation, Tn= n2n is also a solution of the recurrence relation. • Thus the general solution is of the form U = aS+ bT. • We must have U0 = 1 = U1. The last equations become aS0 + bT0= a+ 0b= 1, aS1+ bT1= 2a+ 2b = 1. • Solving for a and b, we obtain a = 1, b = -1/2. • Therefore, the solution is dn= 2n – 1/2n2n = 2n – n2n-1 .
Note • For the general linear homogeneous recurrence relation of order k with constant coefficients c1, c2, …, ck, • if r is a root of tk– c1tk-1 – c2tk-2 – … – ck= 0 of multiplicity m, it can be shown that rn, nrn, … , nm-1rnare solutions of the equation.