{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw02_sol - CS170 Spring 2010 HW2 Solutions 1(DPV 2.5 a T(n...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS170 - Spring 2010 HW2 - Solutions 1. (DPV 2.5) a) T ( n ) = 2 T ( n/ 3) + 1 = Θ( n log 3 2 ) by the Master theorem. b) T ( n ) = 5 T ( n/ 4) + n = Θ( n log 4 5 ) by the Master theorem. c) T ( n ) = 7 T ( n/ 7) + n = Θ( n log n ) by the Master theorem. d) T ( n ) = 9 T ( n/ 3) + n 2 = Θ( n 2 log n ) by the Master theorem. e) T ( n ) = 8 T ( n/ 2) + n 3 = Θ( n 3 log n ) by the Master theorem. f) T ( n ) = 49 T ( n/ 25) + n 3 / 2 log n = Θ( n 3 / 2 log n ). By using the same reasoning used in the proof of the Master Theorem, we see that at level i of the recursion we have 49 i · ( n (25) i ) 3 / 2 · log ( n 25 i ) = ( 49 25 3 / 2 ) i · n 3 / 2 · (log n - i · log25). Since log 25 n i =0 ( 49 25 3 / 2 ) i = Θ(1) we see our expression is O ( n 3 / 2 log n ). Also, T ( n ) is clearly Ω( n 3 / 2 log n ), since this is a lower bound on the running time of the first level of the recursion. g) T ( n ) = T ( n - 1) + 2 = Θ( n ). Since T ( n ) = n i =0 2. h) T ( n ) = T ( n - 1) + n c = n i =0 i c = Θ( n c +1 ) ( c 1 is a constant). Shown in HW1. i) T ( n ) = T ( n - 1) + c n = n i =0 c i = Θ( c n ) ( c > 1 is a constant). Shown in HW1. j) T ( n ) = 2 T ( n - 1) + 1 = n i =0 2 i · Θ(1) = Θ(2 n ). j) T ( n ) = T ( n ) + 1 = Θ(loglog n ). In each level of the recursion we have one process which takes O (1). Therefore T ( n ) + 1 = k i =0 1+ T ( b ) where b is some small enough constant and k is the number of levels of the recursion taken to reach b from n . We need to find k , and plug it into the equation k i =0 1+ T ( b ) to compute the running time. At step i of the recursion the input is of size n ( 1 2 i ) . We need to find k such that n ( 1 2 k ) = b . Doing the math we get k = loglog n - loglog b log2 = Θ(loglog n ), and we see that T ( n ) = k i =0 1 + T ( b ) = Θ(loglog n ). 1
Image of page 1

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

View Full Document Right Arrow Icon
2. (DPV 2.11) Let X = A B C D and Y = E F G H be two n -by- n matrices, where A, B, C, D, E, F, G and H are n/ 2-by- n/ 2 submatrices. For any i n 2 and j n 2 : ( X · Y ) ij = n k =1 X ik · Y kj = n/ 2 k =1 X ik · Y kj + n k = n 2 +1 X ik · Y kj = n/ 2 k =1 A ik · E kj + n/ 2 k =1 B ik · G kj = ( A · E + B · G ) ij A similar proof holds for the values of ( i, j ) in the other sectors of the matrix. 3. (DPV 2.15) We can implement split() as follows: split ( a [1 , . . . , n ] , v ) store =1 for i = 1 to n do if a [ i ] < v then swap a [ i ] and a [ store ] store = store + 1 end if end for for i = store to n do if a [ i ] = v then swap a [ i ] and a [ store ] store = store + 1 end if end for The first for loop passes through the array bringing the elements smaller than v to the front, so splitting
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern