ALGORITHMS QUALIFYING EXAM

UML CS Algorithms Qualifying Exam Fall, 2007 NAME:____________________________________ ALGORITHMS QUALIFYING EXAM This exam is open books and notes...
Author: Reynard Snow
2 downloads 0 Views 548KB Size
UML CS

Algorithms Qualifying Exam

Fall, 2007

NAME:____________________________________ ALGORITHMS QUALIFYING EXAM This exam is open books and notes and closed neighbors and calculators. The upper bound on exam time is 3 hours. Please put all your work on the exam paper. (Partial credit will only be given if your work is shown.) Your pseudocode should use the conventions from: [Cormen2001] Cormen, Leiserson, Rivest, Stein. Introduction to Algorithms, 2nd edition, MIT Press, 2001. If you use pseudocode from a reference, such as [Cormen2001], you can just give the page reference instead of writing that pseudocode on your exam paper. All algorithms referred to here use a sequential model of computation, not a parallel one. Good luck!

1 of 1

UML CS

Algorithms Qualifying Exam

Fall, 2007

1: (5 points) (a) (1 point) Given the following four functions:

h1 (n) = 3• lg2 lg n

h2 (n) = 2 • lg 3lg n

h3 (n) = lg 32•lg n

h4 (n) = lg2 3•lg n

List them below in nondecreasing asymptotic order of growth:

!

1)

2)

3)

smallest

4) largest

Now, given the following 4 facts about unknown functions f1 (n), f 2 (n), f 3 (n), f 4 (n) :

1) f1 (n) " #( h1(n)) 2) f 2 (n) " #( h2 (n))

!

3) f 3 (n) " O( h3 (n)) 4) f 4 (n) " #( h4 (n))

For each statement below, select TRUE if the statement must be true for all choices of the functions f1 (n), f 2 (n), f 3 (n), f 4 (n) consistent with facts (1)-(4). Select FALSE otherwise. ! Briefly justify ! ! your answer. (b) (1 point)

f 3 (n) " O( f1 (n))

TRUE

FALSE

(c) (1!point)

f 4 (n) " !( f 2 (n))

TRUE

FALSE

(d) (1 point)

f 3 (n) ! O( f 4 (n))

TRUE

FALSE

(e) (1 point)

f1 (n) " !( f 2 (n))

TRUE

FALSE

2 of 2

UML CS

Algorithms Qualifying Exam

Fall, 2007

2: (5 points) Find a tight upper and lower bound on the closed-form solution for the following recurrence: * " n % 4 lg n ,8T$ ' + 2 T(n) = + # 4 & ,((1)

. n > k, / n ) k ,0

where k is a small integer. That is, find a function g (n) such that T (n) " !( g (n)) . !

3 of 3

UML CS

Algorithms Qualifying Exam

Fall, 2007

3: (10 points)

!

Mystery(n) if n = 1 then return for i " 1 to n do Mystery(n / 2) for j ! 1 to n do for k ! j to n do print " test message" a) (6 points) A tight upper and lower bound on the worst-case asymptotic running time of Mystery(n) is (circle one): O(n)

O(n2)

O(n3)

O(lgn)

O(nlgn)

O(n2lgn)

Ω(n)

Ω(n2)

Ω(n3)

Ω(lgn)

Ω(nlgn)

Ω (n2lgn) Ω (lglgn)

Θ(n)

Θ(n2)

Θ(n3)

Θ(lgn)

Θ(nlgn)

Θ(n2lgn) Θ(lglgn)

O(lglgn)

none of the above b) (2 point) The answer DOES or DOES NOT (circle one) change for BEST-CASE inputs.

c) (2 point) The answer DOES or DOES NOT (circle one) change for AVERAGE-CASE inputs.

4 of 4

UML CS

Algorithms Qualifying Exam

Fall, 2007

4: (20 points) Given: - a set S of two-dimensional points, - an integer k. Question: Does there exist a set of k frames such that every point of S is contained in at least one frame? A frame is defined in this problem as the union of a horizontal line and a vertical line that both pass through the same point along the line x = y . Prove that this problem is NP-complete.

5 of 5

UML CS

Algorithms Qualifying Exam

Fall, 2007

5: (18 points) A diver is sent to a sunken ship to retrieve as much of its precious cargo’s value as he can bring up before he runs out of oxygen. Each cargo item i is marked by its weight wi and its value vi. Oxygen consumption is linear in the weight of objects being carried out. The diver has a constant readout of how much oxygen he has left in his tank. If he chooses an object that will consume more oxygen than there is left in the tank, he will die. Develop an algorithm to maximize the value of goods retrieved from the ship without killing the diver: i. Choose an approach, justify your choice; ii. Write your algorithm; iii. Show its correctness; iv. Analyze its performance.

6 of 6

UML CS

Algorithms Qualifying Exam

Fall, 2007

6: (18 points) Your delivery company has been hired to deliver an important package to a remote location. The contract stipulates a fixed cost, a time to deliver, and expenses (gas, food, etc.). In addition, your client has offered a bonus of $1 for each hour of earlier delivery, and a $1 for each $10 saved in expenses. There are many roads going through many different cities and towns to destination. Fast highways mean higher fuel costs, big cities carry expensive lodging and food costs, slow back roads through little villages have lower associated costs, but require more time. Design an algorithm to maximize your income from this assignment. Give the algorithm, show its correctness, and analyze its performance.

7 of 7

UML CS

Algorithms Qualifying Exam

Fall, 2007

7: (18 points) A car manufacturer has a set T of m trim T = {T1, T2, …, Tm}. Each trim Tj includes a subset Po of a set O of n options, O = {O1, O2, …, On}. Each option Ok costs ck dollars. The cost of making a car of trim Tj is the sum of the costs of the options in Po plus a unit cost per each option, which represents the cost of labor required to add the option to the car. A car with trim Tj sells for pj dollars. Propose an efficient algorithm to select which trims the manufacturer should offer to maximize profits. (Hint: consider building a network with a source vertex s, vertices for options O1, O2, …, On, for trims T1, T2, …, Tm, and a sink vertex t. Option edges (s, Ok) have capacities ck (the option’s cost); trim edges (Tj, t) have capacities pj (the car’s selling price). If an option Ok is offered in trim Tj, there is an edge (Ok, Tj), of what capacity?) Make sure that you provide the following for your algorithm: (a) (7 points) pseudocode (b) (6 points) worst-case asymptotic running time analysis (c) (7 points) proof that your algorithm maximizes profits.

8 of 8

UML CS

Algorithms Qualifying Exam

DO one of problems 8-11.

9 of 9

Fall, 2007

UML CS

Algorithms Qualifying Exam

Fall, 2007

8: (6 points) For the circuit below, give a satisfying input assignment or show that the circuit is unsatisfiable. (A satisfying assignment is an input assignment that yields an output value of 1.)

in

out

10 of 10

UML CS

Algorithms Qualifying Exam

Fall, 2007

9: (6 points) Consider a set S = {a1 , a2 ,..., an } of n activities. Each activity ai has a start time si and a finish time fi such that si < fi. A compatibility set of S is a subset of activities of S that are mutually compatible (non-overlapping). Suppose that S is such that it has a maximum-sized compatibility set of size n - 1. In this case, find a formula, in terms of n, that represents the average size of a compatibility set of S. You may exclude the empty set from your calculation. For example, if n = 3, your formula should give the answer 13/8.

11 of 11

UML CS

Algorithms Qualifying Exam

Fall, 2007

10: (6 points) Let T be a minimal spanning tree for a graph G, let e be an edge in T, and let T' be T with e removed. Show that e is a minimum weight edge between components of T'.

12 of 12

UML CS

Algorithms Qualifying Exam

Fall, 2007

11: (6 points) In the Floyd-Warshall all-pairs shortest path algorithm there are three nested loops. There are six possible permutations of these three loops. Which ones provide a correct algorithm?

13 of 13