Final-Spring06-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 Final Exam, Spring 2006 Page 1 of 16 University of Waterloo Department of Electrical and Computer Engineering SE 240 Algorithms and Data Structures Spring 2006 Final Examination Instructor: Ladan Tahvildari Date: Tuesday, August 1, 2006 Time: 4:00 p.m. to 6:30 p.m. Duration: 2.5 hours Type: Closed Book Instructions: There are 7 questions. Answer all 7 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. Standard calculator allowed but no additional materials allowed. Name Student ID Question Mark Max Marker 1 15 2 6 3 4 4 15 5 30 6 20 7 10 Total 100
Background image of page 1

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

View Full DocumentRight Arrow Icon
SE240 Final Exam, Spring 2006 Page 2 of 16 Name: Student ID: Question 1: Algorithm Analysis [15] Part A [6]. Consider the following sorting algorithm. NEW-SORT (A, i, j) if A[i] > A[j] then exchange A[i] A[j] if i+1 j then return k ⎯⎯ ⎣⎦ 3 / ) 1 ( + i j /* Round down */ NEW-SORT (A, i, j-k) /* First two-thirds */ NEW-SORT (A, i+k, j) /* Last two-thirds */ NEW-SORT (A, i, j-k) /* First two-thirds again */ a. Give a recurrence for the worst-case running time of NEW-SORT and a tight asymptotic bound on the worse case running time. ) ( ) ( : ) 1 ( , 5 . 1 , 3 ) 1 ( ) ( ) 1 ( ) 3 2 ( 3 ) ( 7 . 2 7 . 2 3 log log 5 . 1 n n T Case Method Master n n n b a n f n T n T a b Θ = = = = = Ο = Θ + = b. Compare the worst-case running time of NEW-SORT with that of insertion sort, merge sort, heapsort, and quick sort. Insertion: ) ( 2 n Θ Merge Sort: ) lg ( n n Θ Heapsort: ) lg ( n n Θ Quicksort: ) ( 2 n Θ NEW-SORT is slower than all of them.
Background image of page 2
SE240 Final Exam, Spring 2006 Page 3 of 16 Name: Student ID: Part B [4]. Let ) ( n f and ) ( n g be asymptotically non-negative functions. Using the basic definition of Θ notation, prove that )) ( ) ( ( )) ( ), ( max( n g n f n g n f + Θ = . By the definition of notation Θ , we must show that there exist positive constant 1 c , 2 c and 0 n for 0 n n > )) ( ) ( ( )) ( ), ( max( )) ( ) ( ( 0 2 1 n g n f c n g n f n g n f c + + without loss the generality , let ) ( )) ( ), ( max( n f n g n f = . Clearly, ) ( 2 ) ( ) ( n f n g n f + . Also, since 0 ) ( n g , ) ( ) ( ) ( n f n g n f + . Thus, selecting 1 , 2 1 2 1 = = c c and 1 0 = n satisfies the definition.
Background image of page 3

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

View Full DocumentRight Arrow Icon
SE240 Final Exam, Spring 2006 Page 4 of 16 Name: Student ID: Part C [5]. Give asymptotic upper and lower bounds for
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.

This note was uploaded on 11/26/2009 for the course CIS 502 taught by Professor Naver during the Spring '09 term at National Tsing Hua University, China.

Page1 / 16

Final-Spring06-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