160 likes | 250 Views
Learn how to solve linear homogeneous recurrence relations with constant coefficients using characteristic equations. Practice finding roots and general solutions. Explore unique solutions by solving for constants in boundary values. Discover how to handle non-homogeneous recurrences and sequence operators. Master the concept of annihilating sequences with operators like (E-1). Plenty of examples provided for better understanding.
E N D
CS 173:Discrete Mathematical Structures Cinda Heeren heeren@cs.uiuc.edu Siebel Center, rm 2213 Office Hours: W 12:30-2:30
CS 173 Announcements • Homework #9 available, due 11/13, 8a. Cs173 - Spring 2004
Giggle. We want to be able to compute T(n), without having to compute T(n-k) To achieve this we “solve” the recurrence. CS 173 Recurrences Linear homogeneous recurrence relations with constant coefficients. Today’s first example: T(n) = 7T(n-1) - 10T(n-2) T(0) = 2, T(1) = 1 • Rewrite: T(n) - 7T(n-1) + 10T(n-2) = 0 • Find characteristic eqn: r2 - 7r + 10 = 0 • Find roots of char eqn: (r-2)(r-5) = 0, r=2,5 • General solution is T(n) = A2n + B5n Cs173 - Spring 2004
CS 173 Recurrences Today’s first example: T(n) = 7T(n-1) - 10T(n-2) T(0) = 2, T(1) = 1 • General solution is T(n) = A2n + B5n Now what? … think about what we know! A20 + B50 = 2 A + B = 2 A = 3, B = -1 A21 + B51 = 1 2A + 5B = 1 • Unique solution is T(n) = 3·2n - 5n Cs173 - Spring 2004
CS 173 Recurrences You try a tricky one: T(n) = T(n-2)/4 T(0) = 1, T(1) = 0 • Rewrite: • Find characteristic eqn: • Find roots of char eqn: • General solution is • Set up system of eqn to get unique soln. Cs173 - Spring 2004
CS 173 Recurrences Suppose the characteristic eqn factors into: (r-2)3(r-3)2(r-5) = 0 Roots are 2,2,2,3,3,5 If you have a non-distinct root r of multiplicity k, then nirn, i=0,1,…k are all solutions. In this case the general solution is: T(n) = A1n22n + A2n2n + A32n + A4n3n + A53n + A65n T(n) = (A1n2 + A2n+ A3)2n + (A4n+ A5)3n + A65n To find the unique particular solution, we would need the 6 boundary values. Solve for A1, …A6 by solving 6 equations in 6 unknowns. Cs173 - Spring 2004
CS 173 Recurrences Here’s one for you to try: an = 4an-1 - 5an-2 + 2an-3, n 3 a0 = 0, a1 = 1, a2 = 2 Cs173 - Spring 2004
CS 173 Recurrences Linear NONhomogeneous recurrence relations with constant coefficients. c0an + c1an-1 + c2an-2 + … + ckan-k = f(n), • constant • polynomial in n • cn for some constant c • cn · polynomial(n) Where f(n) is This is approach is different than the one in your text. Easier and more general. Cs173 - Spring 2004
CS 173 Recurrences First, some notation: A sequence a0, a1, a2, …, is denoted an • 2n = 1,2,4,8,… • n2 = 0,1,4,9,… • n = 0,1,2,3,… Examples Note: if an and bn are sequences, then an + bn represents the sequence an +bn (termwise addition). Cs173 - Spring 2004
CS 173 Recurrences Sequence operators: • Constant multiplication c·an defined to be c·an Ex: 3·2n = 3·2n = 3, 6, 12, 24, 48, … • Shift “E” Ean = an+1 shifts sequence to left Ex: E2n = 2n+1 = 2, 4, 8, 16, … Ex: E3n + 1 = 3(n+1) + 1 = 3n + 4 Cs173 - Spring 2004
CS 173 Recurrences Combining operators: • If A,B are seq ops, then A+B is a seq op: (A+B)an defined to be Aan + Ban Ex: (E+2)2n = E2n + 22n = 2n+1 + 2·2n = 2n+1 + 2n+1 = 2n+1 + 2n+1 = 2·2n+1 = 2n+2 • If A,B are seq ops, then AB is a seq op: (AB)an defined to be A(Ban) Ex: E3an = E·E·Ean = E(E(Ean)) = an+3 Cs173 - Spring 2004
Discrete derivative CS 173 Recurrences An important operator: (E-1) • Example: (E-1)n = En - n = n + 1 - n = n + 1 - n = 1 • More generally: (E-1)an = an+1 - an = an+1 - an • (E-1)n2 = En2 - n2 = (n+1)2 - n2 = n2 + 2n + 1 - n2 = 2n+ 1 Cs173 - Spring 2004
(E-1) “annihilates” c CS 173 Recurrences For any constant sequence c: (E-1)c = 0 • TRICK: to solve a NONhomogeneous linear recurrence with constant coefficients, turn it into a homogeneous recurrence by applying operators to annihilate the right side. Cs173 - Spring 2004
(E-1) “annihilates” c CS 173 Recurrences Example: solve an = 5an-1 - 6an-2 + 4 • Rewrite: an - 5an-1 + 6an-2 = 4 • Rewrite again so n is smallest index: an+2 - 5an+1 + 6an = 4 • Rewrite again as a sequence: an+2 - 5an+1 + 6an = 4 • Rewrite again using operators: (E2 - 5E + 6)an = 4 Cs173 - Spring 2004
(E-1) “annihilates” c Homogeneous!!! CS 173 Recurrences Example: solve an = 5an-1 - 6an-2 + 4 (E2 - 5E + 6)an = 4 • Annihilate right side: (E-1)(E2 - 5E + 6)an = (E-1)4 (E3 - 6E2 + 11E - 6)an = 0 • But that’s just: an+3 - 6an+2 + 11an+1 - 6an = 0 an - 6an-1 + 11an-2 - 6an-3 = 0 Cs173 - Spring 2004
Homogeneous!!! CS 173 Recurrences Example: solve an - 6an-1 + 11an-2 - 6an-3 = 0 • Characteristic equation: (r3 - 6r2 + 11r - 6) = 0 (r-1)(r-2)(r-3) = 0 • General solution: an = A1 + A22n + A33n Cs173 - Spring 2004