Midterm-Spring07-Solutions - University of Waterloo...

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

View Full Document Right Arrow Icon
SE240 Midterm, Spring 2007 Page 1 of 15 University of Waterloo Department of Electrical and Computer Engineering SE 240 Algorithms and Data Structures Spring 2007 Midterm Examination Instructor: Ladan Tahvildari Date: Monday, June 11, 2007, 6:30 p.m. Duration: 1.5 hours Type: Closed Book Instructions: There are 5 questions. Answer all 5 questions. The number in brackets denotes the relative weight of the question (out of 100). If information appears to be missing from a question, make a reasonable assumption, state it and proceed. Write your answers directly on the sheets. If the space to answer a question is not sufficient, use the last (overflow) page. When presenting programs, you may use any mixture of pseudocode/C++/Java constructs as long as the meaning is clear. Name Student ID Question Mark Max Marker 1 20 2 15 3 30 4 15 5 20 Total 100
Background image of page 1

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

View Full Document Right Arrow Icon
SE240 Midterm, Spring 2007 Page 2 of 15 Name: Student ID: Question 1: Algorithm Analysis [20] Part A [10]. You are given a set of n identical sealed boxes, 1 n of which contain one donut and one of which is empty. For convenience, you may assume that k n 2 = for some integer k . To help you find the empty box, you have a balance. At which weighing, you place two sets of boxes on the balance and determine which set is heavier. i) Describe an algorithm to find the empty box which uses ) (log n O weighings. a. Divide boxes into two sets of equal size b. Weigh the sets against each other c. Report (recursively) with lighter set ii) Give a recurrence and solve it to show your algorithm runs in ) (log n O . + = = 2 1 ) 2 / ( 1 0 ) ( n if n W n if n W a=1, b=2 1 0 1 log 2 = = n n f(n)=1=O(1) Then, W(n)=logn
Background image of page 2
SE240 Midterm, Spring 2007 Page 3 of 15 Name: Student ID: Part B. [10] Give asymptotic upper and lower bounds for the following recurrence. Assume that ) ( n T is constant for sufficiently small n . Make your bounds as tight as possible, and justify your answer. n n n T n T 2 ) 2 / ( 4 ) ( + = We have f(n) = n 2 n = n 5/2 Also n log b a = n log 2 4 = n 2 Since n 5/2 = (n 2 + 1/2 ) Case 3 of Master Theorem We have af(n/b) = 4(n/2) 2 n/2 = n 5/2 / 2 < cn 5/2 for 1/ 2 < c < 1 Case 3 applies, and we have T(n) = Θ (n 2 n)
Background image of page 3

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

View Full Document Right Arrow Icon
SE240 Midterm, Spring 2007 Page 4 of 15 Name: Student ID: Question 2: Elementary Data Structures [15] Part A [5].
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 15

Midterm-Spring07-Solutions - University of Waterloo...

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

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