This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS180 Algorithms Midterm Examination Student ID: First name: Middle name: Last name: These are not complete solutions but only the major ideas behind solutions. 1 Problem 1. [15%] Solve the following recurrences. You should only give the solutions in Θnotation and write one line of explanation for each. For simplicity, assume that T ( n ) = 1 for all n ≤ 2. 1. T ( n ) = T ( n 2) + 2 2. T ( n ) = 3 T ( n/ 3) + n 3. T ( n ) = 4 T ( n/ 3) + n 2 4. T ( n ) = T ( √ n ) + 1 5. T ( n ) = 2 T ( √ n ) (Hint: Use the previous one) Solution 1. T ( n ) = Θ( n ). It is similar to T ( n ) = T ( n 1) + 1. 2. T ( n ) = Θ( n log n ). Master Theorem. 3. T ( n ) = Θ( n 2 ). Master Theorem. 4. T ( n ) = log log n . One of the homework problems. 5. T ( n ) = Θ(log n ). Observe that log T ( n ) = log T ( √ n ) + 1 therefore using the previous one: log T ( n ) = log log n which gives the result. 2 Problem 2. [15%] What is the running time in Θnotation (as a function of n ) of the following code? Give a 3line explanation. for x=1 to n do begin y=x; while y>1 do y=y/2; end Solution The while loop takes time log x (it halves x repeatedly). Therefore the run ning time is n X x =1 log x = log(1 · 2 ··· n ) = log( n !) = Θ( n log n ) ....
View Full
Document
 Spring '09
 Naver
 Algorithms

Click to edit the document details