Midterm_sample

Midterm_sample - IE 170 Midterm Examination Practice...

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

View Full Document Right Arrow Icon
Dr. T.K. Ralphs 1. You are given information that the running time of algorithm A is O ( n lg n ) and that the running time of algorithm B is O ( n 3 ). What does this tell you about the relative performance of A and B? 2. Show that n lg n O ( n 3 / 2 ). Is it also true that n lg n o ( n 3 / 2 )? 3. For each pair of functions f and g , state whether f is o , O , Θ, Ω, ω of g (choose as many as apply). Justify your assertion. (a) f ( n ) = lg n , g ( n ) = ln n . (b) f ( n ) = n 1 /n , g ( n ) = 1. (c) f ( n ) = n lg n , g ( n ) = n . 4. Solve the following 3 recurrences. Assume that T (1) = 1. (a) T ( n ) = T ( n - 2) + n/ 2 (b) T ( n ) = 7 T ( n/ 3) + n 2 (c) T ( n ) = T ( n ) + 1 5. Observe that the while loop of lines 5-7 of the insertion sort procedure on page 17 of CLRS uses a linear search to scan through the sorted subarray A [1 . . . j - 1] to find the insertion point. Since the subarray is already sorted, can we improve the worst-case running time by using binary search to find the insertion point? If so, what would be the improved worst-case running time? 6. A generalized queue is a data structure that combines the functionality of a stack, in which the item most recently added to the list is the next to be removed, with that of a standard (FIFO) queue, in which the item least recently added to the list is the next to be removed. In a basic generalized queue interface, the following operations are supported. put : add an item to the queue. getMostRecent : return a copy of the most recently added item and then delete it from the queue. getLeastRecent : return a copy of the least recently added item and then delete it from the queue. empty : indicate whether the queue is empty or not. Note that we don’t have operations to look at items in the queue without deleting them. 1
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
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 5

Midterm_sample - IE 170 Midterm Examination Practice...

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