midterm-sol - CS180 Algorithms Midterm Examination Student...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 3-line 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

Page1 / 6

midterm-sol - CS180 Algorithms Midterm Examination Student...

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

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