sol-quiz1 - CMPT 307 Solutions to Midterm #1 October 14,...

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

View Full Document Right Arrow Icon
CMPT 307 Solutions to Midterm #1 October 14, 2008 NO AIDS ALLOWED. Answer ALL questions on test paper. Use backs of sheets for scratch work. Total Marks: 55 ADVICE: Do this page fast! 1. True or False? All logarithms are base 2. NO JUSTIFICATION IS NECESSARY. [5] (a) 5 n 2 log n O ( n 2 ) (b) 5 n 2 log n Ω( n 2 ) (c) 4 8 n O (8 4 n ) (d) 2 10 log n + 100(log n ) 11 O ( n 10 ) (e) 2 n 2 log n + 3 n 2 Θ( n 3 ) Solution: (b) and (d) are True; the rest are False. 2. Give the asymptotic upper and lower bounds for T ( n ) in the following recurrences. [6] Assume that T ( n ) is constant for n 2. NO JUSTIFICATION IS NECESSARY. (a) T ( n ) = T ( n/ 2) + n Solution: Θ( n ). (b) T ( n ) = 2 T ( n/ 2) + n Solution: Θ( n log n ). (c) T ( n ) = T ( n/ 2) + 1 Solution: Θ(log n ). 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
3. Divide-and-Conquer (a) Design a recursive algorithm for finding a largest element in an input array A [1 ..n ] [10] of natural numbers, by completing the high-level description of the algorithm RecMax given below. Your algorithm RecMax must follow the divide-and- conquer strategy. Using pseudo-code, fill in the gaps after each of the three comments by a piece of code that corresponds to that comment. Algorithm RecMax ( n,A ) Input: array of natural numbers A [1 ..n ] (assume that n is a power of 2). Output: max 1 i n A [ i ] (that is, a maximum element in A [1 ..n ]) if n = 1 then return A [1] % otherwise, create two subinstances of the input instance by % partitioning A [1 ..n ] in two smaller arrays
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/23/2009 for the course CS 307 taught by Professor A.bulatov during the Spring '09 term at Simon Fraser.

Page1 / 5

sol-quiz1 - CMPT 307 Solutions to Midterm #1 October 14,...

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

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