CS 561: Fall 2004, Homework Assignment #3

Due Tuesday, October 5, 2004


Problem 1. Suppose that we only moved the searched element x forward by one location in the array (instead of all the way to the front). This is slightly tricky, because it does not really achieve the goal of making x better than the other elements in terms of "priority" for retrieval unless we take some extra measures. (Imagine just exchanging it with the element y in front of it: only the relative "priorities" of these two elements have been altered and that can be restored immediately by searching next for y.)

Verify that if the operation is to move x forward by a fixed number of locations (some value k, where k is a fixed positive integer), the competitive ratio cannot be bounded. (The argument in the parenthetical remark above shows that such is the case for k=1; you need only generalize it for large values of k.)

In contrast, verify that, if we move x some fixed fraction of the distance to the front (i.e., if x is at index i in the array and our fixed fraction is r, 0 < r < 1, we move x exactly int(r*i) locations forward), we can use the same argument as in MTF to prove that the performance of that heuristic is also within a constant factor of the optimal: what factor do you obtain?

If you are really in the mood for exploration, consider the following strategy: when x is accessed, we will flip a fair coin; if the coin turns heads, we move x forward by one location; otherwise, we leave x where it is. It can be verified that, with high probability, the competitive ratio of this heuristic will be bounded by a constant -- in sharp contrast to the heuristic that always moves x forward by 1. (So that moving x less, rather than more, fixed the problem!)

Problem 2. The worst-case cost of incrementing an arbitrary integer is proportional to the number of words used in representing that integer, since we may have to ripple a carry all the way from the least significant word to the most significant word. Prove that the amortized cost of incrementation is constant, using the potential method; clearly define your potential -- there must be a line in your solution that looks like

Phi() = ...

Problem 3. Write down a formal proof that the amortized cost of both insertion and deletion in dynamic arrays is constant when the array is implemented with the doubling/halving strategy that we discussed in class. Again, be sure to define very clearly your potential function.