04 Recurrences and Lists Solutions

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

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

View Full Document Right Arrow Icon
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 )
Background image of page 1

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

View Full DocumentRight Arrow Icon
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)
Background image of page 2
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)
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
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 &gt;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

Page1 / 10

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online