Download Annihilators - Data Structures and Algorithms - Lecture Slides | CS 361L and more Study notes Computer Science in PDF only on Docsity!
CS 361, Lecture 10
Jared Saia University of New Mexico
Outline
Annihilator Operators
We define three basic operations we can perform on this se- quence:
- Multiply the sequence by a constant: cA = 〈ca 0 , ca 1 , ca 2 , · · · 〉
- Shift the sequence to the left: LA = 〈a 1 , a 2 , a 3 , · · · 〉
- Add two sequences: if A = 〈a 0 , a 1 , a 2 , · · · 〉 and B = 〈b 0 , b 1 , b 2 , · · · 〉, then A + B = 〈a 0 + b 0 , a 1 + b 1 , a 2 + b 2 , · · · 〉
Annihilator Description
- We first express our recurrence as a sequence T
- We use these three operators to “annihilate” T , i.e. make it all 0 ’s
- Key rule: can’t multiply by the constant 0
- We can then determine the solution to the recurrence from the sequence of operations performed to annihilate T
Example
- Consider the recurrence T (n) = 2T (n − 1), T (0) = 1
- If we solve for the first few terms of this sequence, we can see they are 〈 20 , 21 , 22 , 23 , · · · 〉
- Thus this recurrence becomes the sequence:
T = 〈 20 , 21 , 22 , 23 , · · · 〉
Example (II)
Let’s annihilate T = 〈 20 , 21 , 22 , 23 , · · · 〉
- Multiplying by a constant c = 2 gets: 2 T = 〈 2 ∗ 20 , 2 ∗ 21 , 2 ∗ 22 , 2 ∗ 23 , · · · 〉 = 〈 21 , 22 , 23 , 24 , · · · 〉
- Shifting one place to the left gets LT = 〈 21 , 22 , 23 , 24 , · · · 〉
- Adding the sequence LT and − 2 T gives: LT − 2 T = 〈 21 − 21 , 22 − 22 , 23 − 23 , · · · 〉 = 〈 0 , 0 , 0 , · · · 〉
Distributive Property
- The distributive property holds for these three operators
- Thus can rewrite LT − 2 T as (L − 2)T
- The operator (L − 2) annihilates T (makes it the sequence of all 0’s)
- Thus (L − 2) is called the annihilator of T
0, the “Forbidden Annihilator”
- Multiplication by 0 will annihilate any sequence
- Thus we disallow multiplication by 0 as an operation
- In particular, we disallow (c−c) = 0 for any c as an annihilator
- Must always have at least one L operator in any annihilator!
Uniqueness
- An annihilator annihilates exactly one type of sequence
- In general, the annihilator L − c annihilates any sequence of the form 〈a 0 cn〉
- If we find the annihilator, we can find the type of sequence, and thus solve the recurrence
- We will need to use the base case for the recurrence to solve for the constant a 0
Example
If we apply operator (L − 3) to sequence T above, it fails to annihilate T
(L − 3)T = LT + (−3)T = 〈 21 , 22 , 23 , · · · 〉 + 〈− 3 × 20 , − 3 × 21 , − 3 × 22 , · · · 〉 = 〈(2 − 3) × 20 , (2 − 3) × 21 , (2 − 3) × 22 , · · · 〉 = (2 − 3)T = −T
Example (II)
What does (L−c) do to other sequences A = 〈a 0 dn〉 when d 6 = c?:
(L − c)A = (L − c)〈a 0 , a 0 d, a 0 d^2 , a 0 d^3 , · · · 〉 = L〈a 0 , a 0 d, a 0 d^2 , a 0 d^3 , · · · 〉 − c〈a 0 , a 0 d, a 0 d^2 , a 0 d^3 , · · · 〉 = 〈a 0 d, a 0 d^2 , a 0 d^3 , · · · 〉 − 〈ca 0 , ca 0 d, ca 0 d^2 , ca 0 d^3 , · · · 〉 = 〈a 0 d − ca 0 , a 0 d^2 − ca 0 d, a 0 d^3 − ca 0 d^2 , · · · 〉 = 〈(d − c)a 0 , (d − c)a 0 d, (d − c)a 0 d^2 , · · · 〉 = (d − c)〈a 0 , a 0 d, a 0 d^2 , · · · 〉 = (d − c)A
Uniqueness
- The last example implies that an annihilator annihilates one type of sequence, but does not annihilate other types of sequences
- Thus Annihilators can help us classify sequences, and thereby solve recurrences
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
- 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
Factoring
- L^2 − L − 1 is an annihilator that is not in our lookup table
- However, we can factor this annihilator (using the quadratic formula) to get something similar to what’s in the lookup table
- L^2 − L − 1 = (L − φ)(L − φˆ), where φ = 1+
√ 5 2 and ˆφ^ =^
1 −√ 5
Quadratic Equation
“Me fail English? That’s Unpossible!” - Ralph, the Simpsons
High School Algebra Review:
- To factor something of the form ax^2 + bx + c, we use the Quadratic Formula:
- ax^2 + bx + c factors into (x − φ)(x − ˆφ), where:
φ = b^ +
√ b^2 − 4 ac 2 a
φˆ = b^ −
√ b^2 − 4 ac 2 a
Example
- To factor: L^2 − L − 1
- Rewrite: 1 ∗ L^2 − 1 ∗ L − 1, a = 1, b = −1, c = − 1
- From Quadratic Formula: φ = 1+
√ 5 2 and ˆφ^ =^
1 −
√ 5 2
- So L^2 − L − 1 factors to (L − φ)(L − φˆ)
Back to Fibonnaci
- Recall the Fibonnaci recurrence is T (0) = 0, T (1) = 1, and T (n) = T (n − 1) + T (n − 2)
- We’ve shown the annihilator for T is (L − φ)(L − φˆ), where φ = 1+
√ 5 2 and ˆφ^ =^
1 −
√ 5 2
- If we look this up in the “Lookup Table”, we see that the sequence T must be of the form 〈c 1 φn^ + c 2 ˆφn〉
- All we have left to do is solve for the constants c 1 and c 2
- Can use the base cases to solve for these
Finding the Constants
- We know T = 〈c 1 φn^ + c 2 ˆφn〉, where φ = 1+
√ 5 2 and ˆφ^ =^
1 −√ 5 2
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 5
( 1 +
)n − √^1 5
( 1 −
)n
(Amazingly, T (n) is always an integer, in spite of all of the square roots in its formula.)
Todo