Docsity

Midterm Exam on Data Structure Algorithm Analysis | CSC 517, Exams of Computer Science

Partial preview of the text

Download Midterm Exam on Data Structure Algorithm Analysis | CSC 517 and more Exams Computer Science in PDF only on Docsity!

Burton Rosenberg

Midterm October 11, 2004. 1:25–2:15 PM

There are five problems each worth five points for a total of 25 points. Show all your work, partial credit will be awarded. Space is provided on the test for your work; if you use a blue book for additional workspace, sign it and return it with the test. No notes, no collaboration.

Name:

Problem Credit

Total

  1. Indicate for each pair of expression A, B whether A is O, o, Ω, ω or Θ of B. Assume that k ≥ 1 ,  > 0 and c > 1 are constants. Write “yes” or “no” in each box.

A B O o Ω ω Θ n log n n

n 3 n^3 + 40n^2 0. 01 n^3 − n^2 log n log n 1 2 n^ n^1000

  1. Consider the following max-heap:

^ TT

^ TT

%^ %ll

^ ee

^  

HH HH

Show (in pictures) the process of delete max on this heap. Show two iterations of delete max, that is, remove the 18 and then the 16 from the heap.

  1. Suppose that you are given n red and n blue water jugs, all of different shapes and sizes. All red jugs hold different amounts of water, as do the blue ones. Moreover, for every red jug, there is a blue jug that holds the same aount of water, and vice versa. It is your task to find a grouping of the jugs into pairs of red and blue jugs that hold the same amount of water. To do so, you may perform the following operation: pick a pair of jugs in which one is red and one is blue, fill the red jug with water, and then pour the water into the blue jug. The operation will tell you whether the red or the blue jug can hold more water, or if they are the same volume. Assume that such a comparison takes one time unit. Give an Θ(n^2 ) algorithm which determines the grouping. For extra credit, your algorithm will be randomized and have expected run time O(n log n).