Download Annihilators for Linear Recurrences with Multiple Operators - Prof. Jared C. Saia and more Study notes Computer Science in PDF only on Docsity! CS 561, Lecture 4 Jared Saia University of New Mexico Today’s Outline • Annihilators with Multiple Operators • Annihilators for recurrences with non-homogeneous terms • Transformations 1 Multiple Operators • We can apply multiple operators to a sequence • For example, we can multiply by the constant c and then by the constant d to get the operator cd • We can also multiply by c and then shift left to get cLT which is the same as LcT • We can also shift the sequence twice to the left to get LLT which we’ll write in shorthand as L2T 2 Multiple Operators • We can string operators together to annihilate more compli- cated sequences • Consider: T = 〈20 + 30,21 + 31,22 + 32, · · · 〉 • We know that (L−2) annihilates the powers of 2 while leaving the powers of 3 essentially untouched • Similarly, (L − 3) annihilates the powers of 3 while leaving the powers of 2 essentially untouched • Thus if we apply both operators, we’ll see that (L−2)(L−3) annihilates the sequence T 3 The Details • Consider: T = 〈a0 + b0, a1 + b1, a2 + b2, · · · 〉 • LT = 〈a1 + b1, a2 + b2, a3 + b3, · · · 〉 • aT = 〈a1 + a ∗ b0, a2 + a ∗ b1, a3 + a ∗ b2, · · · 〉 • LT − aT = 〈(b − a)b0, (b − a)b1, (b − a)b2, · · · 〉 • We know that (L−a)T annihilates the a terms and multiplies the b terms by b − a (a constant) • Thus (L− a)T = 〈(b − a)b0, (b − a)b1, (b − a)b2, · · · 〉 • And so the sequence (L− a)T is annihilated by (L− b) • Thus the annihilator of T is (L− b)(L− a) 4 Key Point • In general, the annihilator (L − a)(L − b) (where a 6= b) will anihilate only all sequences of the form 〈c1an + c2bn〉 • We will often multiply out (L−a)(L− b) to L2−(a+ b)L+ab • Left as an exercise to show that (L− a)(L− b)T is the same as (L2 − (a + b)L + ab)T 5 Lookup Table • The annihilator L−a annihilates sequences of the form 〈c1an〉 • The annihilator (L − a)(L − b) (where a 6= b) anihilates se- quences of the form 〈c1an + c2bn〉 6 Fibonnaci Sequence • We now know enough to solve the Fibonnaci sequence • Recall the Fibonnaci recurrence is T (0) = 0, T (1) = 1, and T (n) = T (n − 1) + T (n − 2) • Let Tn be the n-th element in the sequence • Then we’ve got: T = 〈T0, T1, T2, T3, · · · 〉 (1) LT = 〈T1, T2, T3, T4, · · · 〉 (2) L2T = 〈T2, T3, T4, T5, · · · 〉 (3) • Thus L2T − LT − T = 〈0,0,0, · · · 〉 • In other words, L2 − L− 1 is an annihilator for T 7 Generalization • It turns out that (L − a)d annihilates sequences of the form 〈p(n)an〉 where p(n) is any polynomial of degree d − 1 • Example: (L − 1)3 annihilates the sequence 〈n2 ∗ 1n〉 = 〈1,4,9,16,25〉 since p(n) = n2 is a polynomial of degree d − 1 = 2 16 Lookup Table • (L− a) annihilates only all sequences of the form 〈c0an〉 • (L−a)(L−b) annihilates only all sequences of the form 〈c0an+ c1b n〉 • (L− a0)(L− a1) . . . (L− ak) annihilates only sequences of the form 〈c0an0 + c1a n 1 + . . . cka n k〉, here ai 6= aj, when i 6= j • (L−a)2 annihilates only sequences of the form 〈(c0n+c1)an〉 • (L − a)k annihilates only sequences of the form 〈p(n)an〉, degree(p(n)) = k − 1 17 Lookup Table (L− a0)b0(L− a1)b1 . . . (L− ak)bk annihilates only sequences of the form: 〈p1(n)an0 + p2(n)a n 1 + . . . pk(n)a n k〉 where pi(n) is a polynomial of degree bi − 1 (and ai 6= aj, when i 6= j) 18 Examples • Q: What does (L− 3)(L− 2)(L− 1) annihilate? • A: c01n + c12n + c23n • Q: What does (L− 3)2(L− 2)(L− 1) annihilate? • A: c01n + c12n + (c2n + c3)3n • Q: What does (L− 1)4 annihilate? • A: (c0n3 + c1n2 + c2n + c3)1n • Q: What does (L− 1)3(L− 2)2 annihilate? • A: (c0n2 + c1n + c2)1n + (c3n + c4)2n 19 Annihilator Method • Write down the annihilator for the recurrence • Factor the annihilator • Look up the factored annihilator in the “Lookup Table” to get general solution • Solve for constants of the general solution by using initial conditions 20 Annihilator Method • Write down the annihilator for the recurrence • Factor the annihilator • Look up the factored annihilator in the “Lookup Table” to get general solution • Solve for constants of the general solution by using initial conditions 21 Lookup Table (L− a0)b0(L− a1)b1 . . . (L− ak)bk annihilates only sequences of the form: 〈p0(n)an0 + p1(n)a n 1 + . . . pk(n)a n k〉 where pi(n) is a polynomial of degree bi − 1 (and ai 6= aj, when i 6= j) 22 Examples • Q: What does (L− 3)(L− 2)(L− 1) annihilate? • A: c01n + c12n + c23n • Q: What does (L− 3)2(L− 2)(L− 1) annihilate? • A: c01n + c12n + (c2n + c3)3n • Q: What does (L− 1)4 annihilate? • A: (c0n3 + c1n2 + c2n + c3)1n • Q: What does (L− 1)3(L− 2)2 annihilate? • A: (c0n2 + c1n + c2)1n + (c3n + c4)2n 23 Example Consider the recurrence T (n) = 7T (n−1)−16T (n−2)+12T (n− 3), T (0) = 1, T (1) = 5, T (2) = 17 • Write down the annihilator: From the definition of the sequence, we can see that L3T − 7L2T + 16LT − 12T = 0, so the annihilator is L3 − 7L2 + 16L− 12 • Factor the annihilator: We can factor by hand or using a computer program to get L3−7L2+16L−12 = (L−2)2(L−3) • Look up to get general solution: The annihilator (L − 2)2(L− 3) annihilates sequences of the form 〈(c0n + c1)2n + c23 n〉 • Solve for constants: T (0) = 1 = c1 + c2, T (1) = 5 = 2c0 + 2c1 + 3c2, T (2) = 17 = 8c0 + 4c1 + 9c2. We’ve got three equations and three unknowns. Solving by hand, we get that c0 = 1,c1 = 0,c2 = 1. Thus: T (n) = n2 n + 3n 24 Example (II) Consider the recurrence T (n) = 2T (n − 1)− T (n − 2), T (0) = 0, T (1) = 1 • Write down the annihilator: From the definition of the se- quence, we can see that L2T−2LT+T = 0, so the annihilator is L2 − 2L + 1 • Factor the annihilator: We can factor by hand or using the quadratic formula to get L2 − 2L + 1 = (L− 1)2 • Look up to get general solution: The annihilator (L−1)2 annihilates sequences of the form (c0n + c1)1 n • Solve for constants: T (0) = 0 = c1, T (1) = 1 = c0 + c1, We’ve got two equations and two unknowns. Solving by hand, we get that c0 = 0,c1 = 1. Thus: T (n) = n 25 At Home Exercise Consider the recurrence T (n) = 6T (n−1)−9T (n−2), T (0) = 1, T (1) = 6 • Q1: What is the annihilator of this sequence? • Q2: What is the factored version of the annihilator? • Q3: What is the general solution for the recurrence? • Q4: What are the constants in this general solution? (Note: You can check that your general solution works for T (2)) 26 Non-homogeneous terms • Consider a recurrence of the form T (n) = T (n − 1) + T (n − 2) + k where k is some constant • The terms in the equation involving T (i.e. T (n − 1) and T (n − 2)) are called the homogeneous terms • The other terms (i.e.k) are called the non-homogeneous terms 27