University of Delaware Computer and Information Sciences CIS621 Algorithm Design and Analysis Homework Set #3 Due Thursday, October 26, 1995

A word on the numbering schemes: Textbook exercises have the form C.S-n, where C is the chapter number, S is the section number and n is the exercise number. Similarly. end-of-chapter problems are denoted C-n. Both kinds often have parts (a), (b), etc. What a flurry of hyphens, dots, and parentheses! Further, when assigned as homework, the problems also get a homework set number and number-within-set. Should we also hypenate such numbers? All of this numbering is too much for me, so from now on homework numbering will be consecutinve throughout the course. There have been 9 problems in sets 1 and 2, so numbering here begins with 10. Unadorned problem numbers, like ”11”, refer to homework problem numbers, Hyphens and dots indicate reference to the text numbering scheme. Great, all is unambiguous. Uh, one more thing: extra credit problems will be labeled EC-n. EC-1 was problem 6 of homework set 2, and EC-2 is given below.

Apropos median, order statistics:

10. Let S be a set of n integers (unordered), and let B be another integer. Give a linear time algorithm for finding M, a maximum cardinality subset of S, such that the sum of the integers in M does not exceed B.

11. You are given n integers - they are NOT sorted. Develop a linear time algorithm to find the largest gap that would occur between consecutive numbers when the n numbers are sorted. For example, given [23, 7, 1, 35, 10, 27, 50, 41], the algorithm should produce 13 as its result, since the sorted list is [1, 7, 10, 23, 27, 35, 41, 50], and the largest gap is 13 (between 10 and 23).

Please note that your algorithm cannot actually sort the n numbers, since general sorting requires time Ω(n lg n).

Apropos binomial heaps:

12. Consider the binomial heap operations Make Heap, Insert, Union, and Extract-Min.

a) Give an example for each of the operation types, Insert, Union, and Extract-Min, to show that the worst case time for an individual operation is Θ^{∞} (lg(n)). See problem 2-5 for definition of Θ^{∞}.

b) Give an amortized analysis for sequences of m binomial heap operations Make Heap, Insert, Union, and Extract-Min such that the amortized cost of the operations is O(1) for Make Heap, Insert, and Union and O(lg n) for Extract-Min.

Hint: use the potential function Φ(n) = ∑(t_{i} +l_{i}), where t_{i} is the number of trees (roots) in the i-th heap currently existing and l_{i} is the highest degree of any tree in the i-th heap currently existing. (let l_{i} be 0 for a empty heap as well as for a heap of one node). A heap comes into existence by Make Heap. Note that Union(H1, H2) makes H1 into the union of the two heaps. Consider it to eliminate the heap H2.

c) Give a sequence of operations to show that an amortization which assigns a cost of O(1) to Decrease-Key is not possible for Binomial Heaps.

Side remark with respect to problem 12: We are then left with the following picture:

Binomial Heap  Fibonacci Heap
worst case amortized worst case amortized
Insert O(lg(n))  Θ(1)  Θ(1)  Θ(1)
Union O(lg(n))  Θ(1)  Θ(1)  Θ(1)
ExMin Θ(lg(n)) Θ(lg(n))  Θ(n)  O(lg(n))
DecKey Θ(lg(n)) Θ(lg(n))  Θ(1)  Θ(1)
Delete Θ(lg(n)) Θ(lg(n))  Θ(n)  O(lg(n))

Apropos union find analysis (more or less – lg* and all that):

13. Consider the following game: I think of a positive number n, which you are to determine by guessing numbers and being told whether each guess is too high or too low or is n. There is no a priori upper bound on n – I am free to pick any n.

a) Give a strategy for determining n using at most 2 lg n + c guesses (c is a constant).

b) Give a strategy for determining n using at most lg n + 2lglgn + k guesses (k is a constant).

To think about: Can you do better than the solution in part b?

EC-2. Problem 20.1, 2-3-4 heaps.

Remember to put your solutions to separate problems on separate pages and to put your name on each.