04 Recurrences and Lists Solutions

# 04 Recurrences and Lists Solutions - log b a = n log n/n =...

This preview shows pages 1–10. Sign up to view the full content.

Master method Example 1: T(n) = 9T(n/3) + n a=9 b=3 f(n)=n n log b a = n log 3 9 = n 2 [ f(n) is smaller than n log b a ] Since f(n) = O(n) = O(n log 3 9 ± ε ), where ε = 1 > 0, case 1 applies. Thus, T(n) = θ (n log b a )= θ (n 2 )

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Master method Example 2: T(n) = T(2n/3) + 1 a=1 b=3/2 f(n)=1 n log b a = n log 3/2 1 = n 0 = 1 [ f(n) is the same size as n log b a ] Since f(n) = θ (n log b a ) = θ (1), case 2 applies. Thus, T(n) = θ (n log b a log n)= θ (log n)
Master method Example 3: T(n) = 3T(n/4) + n log n a=3 b=4 f(n)=n log n n log b a = n log 4 3 = n 0.793 [ f(n) is greater than n log b a for large n ] f(n) = n log n = Ω (n log 4 3 + ε ), where ε = 0.2 and a f(n/b) = 3(n/4)log(n/4) ¾ n log n = c f(n) for n > 0, c = ¾ < 1, so case 3 applies. Thus, T(n) = θ (f(n))= θ (n log n)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Master method Example 4: T(n) = 2T(n/2) + n log n a=2 b=2 f(n)=n log n n log b a = n log 2 2 = n f(n) = n log n = Ω (n). But f(n) is not in Ω (n 1+ ε ). That is, f(n) is not polynomially larger than n log b a : f(n)/n

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: log b a = ( n log n )/n = log n is asymptotically less than n ε for any ε >0. Master method Example 4: T(n) = 2T(n/2) + n log n a=2 b=2 f(n)=n log n This example falls in between cases 2 and 3, so the master method cannot be used FYI: The actual complexity is θ ( n log 2 n) Quiz Break Suppose we have the following lists: A = 1,2,3 B = 4 C = 5,6,7 D = A.join(B) E = A.join(C) Draw a picture that shows A, B, C, D, and E, assuming version 1, and then version 2, of join. Quiz Answer, version 1 join A 1 2 3 empty B 4 empty C 5 6 7 empty Quiz Answer, version 1 join A 1 2 3 B 4 C 5 6 7 empty D E Quiz Answer, version 2 join A 1 2 3 empty B 4 empty C 5 6 7 empty Quiz Answer, version 2 join A 1 2 3 empty B 4 empty C 5 6 7 empty 1 2 3 D 1 2 3 E...
View Full Document

{[ snackBarMessage ]}

### Page1 / 10

04 Recurrences and Lists Solutions - log b a = n log n/n =...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online