Docsity

Annihilators for Linear Recurrences with Multiple Operators - Prof. Jared C. Saia, Study notes of Computer Science

Toggle sidebar
bg1
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 cand then by
the constant dto get the operator cd
•We can also multiply by cand then shift left to get cLTwhich
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=h20+ 30,21+ 31,22+ 32,···i
•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
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

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

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 L^2 T

Multiple Operators

  • We can string operators together to annihilate more compli- cated sequences
  • Consider: T = 〈 20 + 3^0 , 21 + 3^1 , 22 + 3^2 , · · · 〉
  • 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

The Details

  • Consider: T = 〈a^0 + b^0 , a^1 + b^1 , a^2 + b^2 , · · · 〉
  • LT = 〈a^1 + b^1 , a^2 + b^2 , a^3 + b^3 , · · · 〉
  • aT = 〈a^1 + a ∗ b^0 , a^2 + a ∗ b^1 , a^3 + a ∗ b^2 , · · · 〉
  • LT − aT = 〈(b − a)b^0 , (b − a)b^1 , (b − a)b^2 , · · · 〉
  • 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)b^0 , (b − a)b^1 , (b − a)b^2 , · · · 〉
  • And so the sequence (L − a)T is annihilated by (L − b)
  • Thus the annihilator of T is (L − b)(L − a)

Key Point

  • In general, the annihilator (L − a)(L − b) (where a 6 = b) will anihilate only all sequences of the form 〈c 1 an^ + c 2 bn〉
  • We will often multiply out (L − a)(L − b) to L^2 − (a + b)L + ab
  • Left as an exercise to show that (L − a)(L − b)T is the same as (L^2 − (a + b)L + ab)T

Lookup Table

  • The annihilator L−a annihilates sequences of the form 〈c 1 an〉
  • The annihilator (L − a)(L − b) (where a 6 = b) anihilates se- quences of the form 〈c 1 an^ + c 2 bn〉

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 = 〈T 0 , T 1 , T 2 , T 3 , · · · 〉 (1) LT = 〈T 1 , T 2 , T 3 , T 4 , · · · 〉 (2) L^2 T = 〈T 2 , T 3 , T 4 , T 5 , · · · 〉 (3)
  • Thus L^2 T − LT − T = 〈 0 , 0 , 0 , · · · 〉
  • In other words, L^2 − L − 1 is an annihilator for T

Finding the Constants

  • We know T = 〈c 1 φn^ + c 2 φˆn〉, where φ = 1+

√ 5 2 and ˆφ^ =^

1 − √ 5 2

  • We know

T (0) = c 1 + c 2 = 0 (6) T (1) = c 1 φ + c 2 φˆ = 1 (7)

  • We’ve got two equations and two unknowns
  • Can solve to get c 1 = √^15 and c 2 = − √^15 ,

The Punchline

  • Recall Fibonnaci recurrence: T (0) = 0, T (1) = 1, and T (n) = T (n − 1) + T (n − 2)
  • The final explicit formula for T (n) is thus:

T (n) =

( 1 +

)n −

( 1 −

)n

(Amazingly, T (n) is always an integer, in spite of all of the square roots in its formula.)

A Problem

  • Our lookup table has a big gap: What does (L − a)(L − a) annihilate?
  • It turns out it annihilates sequences such as 〈nan〉

Example

(L − a)〈nan〉 = 〈(n + 1)an+1^ − (a)nan〉 = 〈(n + 1)an+1^ − nan+1〉 = 〈(n + 1 − n)an+1〉 = 〈an+1〉 (L − a)^2 〈nan〉 = (L − a)〈an+1〉 = 〈 0 〉

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 〈n^2 ∗ 1 n〉 = 〈 1 , 4 , 9 , 16 , 25 〉 since p(n) = n^2 is a polynomial of degree d − 1 = 2

Lookup Table

  • (L − a) annihilates only all sequences of the form 〈c 0 an〉
  • (L−a)(L−b) annihilates only all sequences of the form 〈c 0 an+ c 1 bn〉
  • (L − a 0 )(L − a 1 )... (L − ak) annihilates only sequences of the form 〈c 0 an 0 + c 1 an 1 +... ckank 〉, here ai 6 = aj, when i 6 = j
  • (L − a)^2 annihilates only sequences of the form 〈(c 0 n + c 1 )an〉
  • (L − a)k^ annihilates only sequences of the form 〈p(n)an〉, degree(p(n)) = k − 1

Lookup Table

(L − a 0 )b^0 (L − a 1 )b^1... (L − ak)bk

annihilates only sequences of the form:

〈p 1 (n)an 0 + p 2 (n)an 1 +... pk(n)ank 〉

where pi(n) is a polynomial of degree bi − 1 (and ai 6 = aj, when i 6 = j)

Examples

  • Q: What does (L − 3)(L − 2)(L − 1) annihilate?
  • A: c 01 n^ + c 12 n^ + c 23 n
  • Q: What does (L − 3)^2 (L − 2)(L − 1) annihilate?
  • A: c 01 n^ + c 12 n^ + (c 2 n + c 3 )3n
  • Q: What does (L − 1)^4 annihilate?
  • A: (c 0 n^3 + c 1 n^2 + c 2 n + c 3 )1n
  • Q: What does (L − 1)^3 (L − 2)^2 annihilate?
  • A: (c 0 n^2 + c 1 n + c 2 )1n^ + (c 3 n + c 4 )2n

Example

Consider the recurrence T (n) = 7T (n − 1) − 16 T (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 L^3 T − 7 L^2 T + 16LT − 12 T = 0, so the annihilator is L^3 − 7 L^2 + 16L − 12
  • Factor the annihilator: We can factor by hand or using a computer program to get L^3 − 7 L^2 +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 〈(c 0 n + c 1 )2n^ + c 23 n〉
  • Solve for constants: T (0) = 1 = c 1 + c 2 , T (1) = 5 = 2 c 0 + 2c 1 + 3c 2 , T (2) = 17 = 8c 0 + 4c 1 + 9c 2. We’ve got three equations and three unknowns. Solving by hand, we get that c 0 = 1,c 1 = 0,c 2 = 1. Thus: T (n) = n 2 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 L^2 T − 2 LT +T = 0, so the annihilator is L^2 − 2 L + 1
  • Factor the annihilator: We can factor by hand or using the quadratic formula to get L^2 − 2 L + 1 = (L − 1)^2
  • Look up to get general solution: The annihilator (L − 1)^2 annihilates sequences of the form (c 0 n + c 1 )1n
  • Solve for constants: T (0) = 0 = c 1 , T (1) = 1 = c 0 + c 1 , We’ve got two equations and two unknowns. Solving by hand, we get that c 0 = 0,c 1 = 1. Thus: T (n) = n

At Home Exercise

Consider the recurrence T (n) = 6T (n − 1) − 9 T (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))

Non-homogeneous terms

  • Consider a recurrence of the form T (n) = T (n − 1) + T (n −
      • 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

Example

  • In a height-balanced tree, the height of two subtrees of any node differ by at most one
  • Let T (n) be the smallest number of nodes needed to obtain a height balanced binary tree of height n
  • Q: What is a recurrence for T (n)?
  • A: Divide this into smaller subproblems
    • To get a height-balanced tree of height n with the smallest number of nodes, need one subtree of height n − 1, and one of height n − 2, plus a root node
    • Thus T (n) = T (n − 1) + T (n − 2) + 1

Example

  • Let’s solve this recurrence: T (n) = T (n − 1) + T (n − 2) + 1 (Let Tn = T (n), and T = 〈Tn〉)
  • We know that (L^2 −L−1) annihilates the homogeneous terms
  • Let’s apply it to the entire equation: (L^2 − L − 1)〈Tn〉 = L^2 〈Tn〉 − L〈Tn〉 − 1 〈Tn〉 = 〈Tn+2〉 − 〈Tn+1〉 − 〈Tn〉 = 〈Tn+2 − Tn+1 − Tn〉 = 〈 1 , 1 , 1 , · · · 〉

Example

  • This is close to what we want but we still need to annihilate 〈 1 , 1 , 1 , · · · 〉
  • It’s easy to see that L − 1 annihilates 〈 1 , 1 , 1 , · · · 〉
  • Thus (L^2 − L − 1)(L − 1) annihilates T (n) = T (n − 1) + T (n −
      • 1
  • When we factor, we get (L−φ)(L− φˆ)(L−1), where φ = 1+

√ 5 2 and ˆφ = 1 −

√ 5

Lookup

  • Looking up (L − φ)(L − φˆ)(L − 1) in the table
  • We get T (n) = c 1 φn^ + c 2 φˆn^ + c 31 n
  • If we plug in the appropriate initial conditions, we can solve for these three constants
  • We’ll need to get equations for T (2) in addition to T (0) and T (1)

Another Example

  • Consider T (n) = T (n − 1) + T (n − 2) + n^2.
  • The residue is 〈 1 , 4 , 9 , 16 , · · · 〉 and
  • The annihilator is (L^2 − L − 1)(L − 1)^3.

Another Example

  • Consider T (n) = T (n − 1) + T (n − 2) + n^2 − 2 n.
  • The residue is 〈 1 − 1 , 4 − 4 , 9 − 8 , 16 − 16 , · · · 〉 and the
  • The annihilator is (L^2 − L − 1)(L − 1)^3 (L − 2).

In Class Exercise

  • Consider T (n) = 3 ∗ T (n − 1) + 3n
  • Q1: What is the homogeneous part, and what annihilates it?
  • Q2: What is the non-homogeneous part, and what annihi- lates it?
  • Q3: What is the annihilator of T (n), and what is the general form of the recurrence?