midsol07 - University of Toronto ECE-345: Algorithms and...

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

View Full Document Right Arrow Icon
University of Toronto ECE-345: Algorithms and Data Structures Solutions to Midterm Examination (Fall 2007) 1. (a) A ( n ) = Θ( n log 5 (3) ) (b) We can draw a recursion tree like we did in class. At one part of the tree goes n/ 5-th of the work while on the other part it goes 4 n/ 5 of the work for the recurrence. Clearly, at each level we do Θ( n ) work while the number of tree levels is log 5 / 4 n = Θ(log n ). Therefore, B ( n ) = Θ( n log n ) 2. (a) Function foo is similar to quicksort, except that it recurs in only one of the two subarrays formed by partition . The call foo(a,1,N,k) will return the k -th smallest number in the array. Namely, after each partitioning, element a [ i ] is in its ±nal place. If k = i , we are done. Otherwise, the k -th smallest number must be in a [ l ] , a [ l +1] , ··· , a [ i - 1] if k < i , and in a [ i +1] , a [ i +2] , ··· , a [ r ] if k > i , so that we can recursively solve the problem by searching in the proper subarray. (b) The worst-case time complexity occurs when
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/29/2012 for the course ECE 345 taught by Professor Veneris during the Fall '10 term at University of Toronto- Toronto.

Page1 / 2

midsol07 - University of Toronto ECE-345: Algorithms and...

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

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