Design of Algorithms - Homework IV

K. Subramani LCSEE, West Virginia University, Morgantown, WV {ksmani@csee.wvu.edu}

1 Instructions

(i) The homework is due on May 3, in my office.

(ii) Attempt as many problems as you can. You will get partial credit, as per the policy discussed in class.

2 Problems

1. You are given a set of n tasks S = {a_{1}, a_{2}, …, a_{n}}, with task a_{i} requiring p_{i} units of time to complete. At any point in time, only one task can be executed. Furthermore, the tasks are non-preemptive, in that once task a_{i} commences, it must run uninterrupted for p_{i} units of time. Design an algorithm that schedules the tasks so as to minimize the average completion time. Argue the correctness of your algorithm. Note that if you have two tasks a_{1} and a_{2} with processing times 3 and 5 respectively and a_{1} is scheduled before a_{2}, then the average completion time is \frac{1}{2}(3 + (3 + 5)).

2. Consider a set of n jobs S = {a_{1}, a_{2}, …, a_{n}}, with task a_{i} having processing time t_{i}, profit p_{i} and a deadline d_{i}. There is only one machine to schedule the jobs and the jobs are non-preemptive. If job a_{i} completes before its deadline d_{i}, you receive a profit p_{i}; otherwise, your profit is 0. Design an algorithm to schedule the jobs so that the profit obtained is maximized. You may assume that all processing times are integers in the set {1, 2, …, n}.

3. In the Fractional Knapsack problem, you are given n objects O = {o_{1}, o_{2}, …, o_{n}} with respective weights W = {w_{1}, w_{2}, …, w_{n}} and respective profits P = {p_{1}, p_{2}, …, p_{n}}. The goal is to pack these objects into a knapsack of capacity M, such that the profit of the objects in the knapsack is maximized, while the weight constraint is not violated. You may choose a fraction of an object, if you so decide; if α_{i}, 0 ≤ α_{i} ≤ 1 of object o_{i} is chosen, then the profit contribution of this object is α_{i} · o_{i} and its weight contribution is α_{i} · w_{i}. Design an algorithm for this problem and argue its correctness.

4. Consider an ordinary binary min-heap data structure that supports the instructions Insert() and Extract-Min() in O(log n) worst-case time. Design a potential function Φ such that the amortized cost of Insert() is O(log n) and the amortized cost of Extract-Min() is O(1). Prove that your potential function is valid, over any sequence of n operations.

5. Design a data structure that supports the following two operations for a set S of integers: Insert(S, x) inserts x into set S, and Delete-Larger-Half(S) deletes the largest ⌈\frac{|S|}{2}⌉ elements from S.

Explain how to implement the data structure so that any sequence of m operations runs in O(m) time.