160 likes | 404 Views
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 #10 available, due 11/20, 8a. CS 173 Recurrences. Linear NONhomogeneous recurrence relations with constant coefficients.
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 #10 available, due 11/20, 8a. 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
(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 • Not a coincidence that characteristic equation looks the same as the annihilating operator: f(r)=0 corresponds exactly to g(E)an = 0 Cs173 - Spring 2004
How? CS 173 Recurrences Technique: • Rewrite recurrence in sequence notation. • Rewrite left side as OPan. • Find an annihilator for sequence on right side and apply to both sides • Read characteristic equation off left side. • Solve homogeneous equation as before. Cs173 - Spring 2004
Use operator (E - 1) “Discrete derivative” CS 173 Recurrences So far we know how to annihilate c for constant c. 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 Cs173 - Spring 2004
Use operator (E - 1) “Discrete derivative” (E - 1)an = Ean - an = an+1 - an = an+1 - an CS 173 Recurrences Group challenge: find the annihilators for the remaining function types. 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 Cs173 - Spring 2004
Use operator (E - 1) “Discrete derivative” (E - 1)an = Ean - an = an+1 - an = an+1 - an Annihilator: (E - 1)k+1 CS 173 Recurrences Group challenge: find the annihilators for the remaining function types. Linear NONhomogeneous recurrence relations with constant coefficients. c0an + c1an-1 + c2an-2 + … + ckan-k = f(n), • constant • polynomial in n of degree k Where f(n) is Cs173 - Spring 2004
CS 173 Recurrences How do you annihilate cn? Consider 3n: E3n = 33n = 3, 9, 27, … 3, 9, 27, … So (E-3)3n = 0 In general (E-c) annihilates cn Cs173 - Spring 2004
CS 173 Recurrences Table of handy annihilators: Sequence Annihilator Cs173 - Spring 2004
CS 173 Recurrences Another little helpful fact: Suppose operator A annihilates an And B annihilates bn Then AB annihilates an +bn Cs173 - Spring 2004
CS 173 Recurrences Solve an = 2an-1 + 2n - 1, a0 = 0. Rewrite as sequences: an - 2an-1 = 2n - 1 an+1 - 2an = 2n+1 - 1 Rewrite using operators: (E-2)an = 2n+1 - 1 Rewrite right side as sum: (E-2)an = 2n+1 - 1 Apply annihilators to both sides: (E-2)(E-1)(E-2)an = (E-2)(E-1) (2n+1 - 1) =0 Write down general soln: an = (A1 + A2n)2n + A3 Cs173 - Spring 2004
an = (n - 1)2n + 1 CS 173 Recurrences Solve an = 2an-1 + 2n - 1, a0 = 0. General solution: an = (A1 + A2n)2n + A3 Need 3 initial values because we have 3 unknowns to solve for. A1 = 2(0) + 21 - 1 = 1, A2 = 2(1) + 22 - 1 = 5 Solve 3 equations in 3 unknowns (using the general solution): A1 + A3 = 0 2A1 + 2A2 + A3 = 1 4A1 + 8A2 + A3 = 1 A1 = -1, A2 = A3 = 1 Cs173 - Spring 2004
Mergesort # of comparisons CS 173 Recurrences Solve an = 2an/2 + n-1, a1 = 0. Cs173 - Spring 2004