cos423: Theory of Algorithms | handout #2 |
Michael Goldwasser | |
Princeton University | Tuesday, February 3, 1998 |
Homework #1: | Asymptotics and algorithm analysis |
Due Date: | Tuesday, February 10, 1998 (9:00am) |
[Note: We do not require formal proof for this problem, simply the ordering and the equivalence classes.]
Let f(n) and g(n) be asymptotically positive functions. Prove or disprove each of the following conjectures.
[Your proofs must be formal, although for false conjectures a specific counterexample would constitute a valid proof.]
Amortized weight-balanced trees
Consider an ordinary binary search tree augmented by adding to each node x the field size[x] giving the number of keys stored in the subtree rooted at x. Let be a constant in the range . We say that a given node x is -balanced if
and
.
The tree as a whole is -balanced if every node in the tree is -balanced. The following amortized approach to maintaining weight-balanced trees was suggested by G. Varghese.
For the remainder of this problem, assume that the constant is strictly greater than 1/2. Suppose that Insert and Delete are implemented as usual for an n-node binary search tree, except that after every such operation, if any node in the tree is no longer -balanced, then the subtree rotted at the highest such node in the tree is ``rebuilt'' so that it becomes 1/2-balanced.
We shall analyze this rebuilding scheme using the potential method. For a node x in a binary search tree T, we define
and we define the potential of T as
where c is a sufficiently large constant that depends on .
An array A[1..n] contains all the integers from to n except one. It would be easy to determine the missing integer in O(n) time by using an auxiliary array B[0..n] to record which numbers appear in A. In this problem, however, we cannot access an entire integer in A with a single operation. The elements of A are represented in binary, and the only operation we can use to access them is ``fetch the jth bit of A[i],'' which takes constant time.
Show that if we use only this operation, we can still determine the missing integer in O(n) time.
[To make the analysis cleaner, we will charge your algorithm only for the number of ``bit-fetch'' operations. The input to the algorithm consists of an array of n numbers, each of which is comprised of bits. Give an algorithm which can find the missing number by fetching only O(n) bits.]
Copyright © 1993, 1994, 1995, 1996, 1997, Nikos Drakos, Computer Based Learning Unit, University of Leeds.