## Exam 3

### Instructions

• The quiz consists of five questions. Be sure that you have all of these and that they are all legible.

• Read all questions and their instructions thoroughly before you begin. It is always worth your time to plan ahead!

• You have also been given two blank pages. Use these sheets for your quiz answers. Be sure to write your name on each sheet.

• The quiz is worth 60 points. Each question is worth twelve points.

• Points will be awarded based on your explicit answers. Partial credit will be given where possible, so show all of your work.

• Whenever you are asked to answer or describe "briefly", a one- or two- sentence response should be enough to express the solution.

• You may keep the quiz questions when you are done, for future reference.

• The quiz lasts forty-five (45) minutes. It is due at 1:45 PM.

### Problems

 Use this problem description for Problems 1-2. Let A = [ a1, a2, ... an ] be an array of integers. We would like to find d, the distance between the two closest numbers in the array. The distance between any two numbers ai and aj is |ai - aj|. For example, if A = [9, 14, 25, 6, 16], then d = 2.

1. Design a brute force algorithm to compute d. How many times does this algorithm compare two distances?

2. Use presorting to design an algorithm to compute d. How many times does this algorithm compare two distances?

• What are the two components of a Bloom filter? How are they related?
• How is a Bloom filter able to be so efficient in space and time?
• In what way is a Bloom filter a "probabilistic data structure"?

4. We would like to use a heapsort to sort the letters in my name, EUGENE, in ascending order.

• Use the top-down algorithm to construct a heap containing these letters.
• Show the state of the heap after performing three deletions.

You may use either a tree implementation or an array implementation for your heap. Be sure to use a parental dominance rule where a node is all of its children, not strictly <. You will receive partial credit for using the bottom-up algorithm to construct the heap.

5. Network Services is considering consolidating all of its on-campus labs into a single lab, in the basement of Maucker Union. They want to know the maximum number of users they will have at any point in time, so that know how many computers they will need in the consolidated lab.

To help us help them solve this problem, they have created a large number of data files, one for each day of the year. Each file contains an even number of integers, in pairs that correspond to the login time and session length for every lab user on campus on that day. For example, a file that contains:

```                0115 47
0737 3
1104 78
1852 422
```

records four users. The first logged in at 1:15 AM and worked for 47 minutes. The last logged in at 6:52 PM and worked for 7 hours, 2 minutes. (He must have had an algorithms project to do!)

Use the Sliding Delta pattern to design an algorithm to find the maximum number of users at any point in time last year.

Eugene Wallingford ..... wallingf@cs.uni.edu ..... April 17, 2014