1 / 8

CSC 3323 Notes – Recurrence Relations

CSC 3323 Notes – Recurrence Relations. Algorithm Analysis. Recurrence Relations. Applying a “divide and conquer” approach to solving a problem will frequently lead to a recursive algorithm. Time complexity for such an algorithm is represented with a recurrence relation.

magee
Download Presentation

CSC 3323 Notes – Recurrence Relations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 3323 Notes – Recurrence Relations Algorithm Analysis

  2. Recurrence Relations • Applying a “divide and conquer” approach to solving a problem will frequently lead to a recursive algorithm. • Time complexity for such an algorithm is represented with a recurrence relation.

  3. Algorithm comparison example Block multiplication (BM): if n ≤ 3 then return SM(x, y) m = n div 2 (rounded up) P1 = BM( X[0..m-1], Y[0..m-1]) P2 = BM( X[m..n-1], Y[m..n-1]) P3 = BM( Add( X[0..m-1], X[m..n-1]), Add( Y[0..m-1], Y[m..n-1])) D = Sub( Sub( P3, P1), P2) Z[0..2m-1] = P1 Z[2m..2n-1] = P2 Z[m..2n-1] = Add( D[0..2m+1], Z[m..2n-1]) return Z

  4. Recurrence Relations: Block Multiplication TBM(n) = 3 * TBM(n/2) + c * n 3 * TBM(n/2) = 3 * ( 3TBM(n/4) + c * (n/2)) 32 * TBM(n/4) = 32 * ( 3TBM(n/8) + c * (n/4)) ……. 3(log2(n)-1) * TBM(2) = 3(log2(n)-1) * ( 3TBM(1)+c*(2)) log2(n)-1 TBM(n)=3log2(n)*TBM(1) + cn∑ (3i/2i)(see formula, p. 8, 6) = nlog2(3) * TBM(1) +cn(((3/2)log2(n)-1)/(3/2-1)) = nlog2(3) * TBM(1) + c’n((n)log2(3/2)-1) TBM(n) ε O(nlog2(3))for 32 bits, 322/321.59 = 4.15 for 64 bits, 642/641.59 = 5.5

  5. Recurrence Relations: Binary Search TBS(n) = TBS(n/2) + c TBS(n/2) = TBS(n/4) + c TBS(n/4) = TBS(n/8) + c ……. TBS(2) = TBS(1)+c TBS(n) = TBS(1) + c*log2(n) TBS(n) ε O(log2(n))

  6. Recurrence Relations • (Section 3.7.1, pp. 137ff) • Generally, for a recurrence relation: T(n) = a*T(n/b) + c n e (See Theorem 3.17, p. 139) T(n) = c’ nlogb(a) + c ne logb(n) if a/be = 1 T(n) = c’ nlogb(a) + c (nlogb(a) – ne) otherwise

  7. Recurrence Relations:Fibonacci numbers • Definition: fib(i) = fib(i-1) + fib(i-2) T(n) = T(n-1) + T(n-2) + c ≥ 2T(n-2) + c 2 T(n-2) ≥ 2(2 T(n-4) + c) …… 2n/2-1T(2) ≥ 2n/2-1 (2T(0) + c) n/2 T(n) ≥ 2n/2T(0)+c ∑ 2i = 2T(0)+c(2n/2 - 1)εΩ(2n/2) i=0

  8. Recurrence relations • Sample problems: pp. 141-145 • 3.4, 3.7, 3.8, 3.10, 3.12

More Related