Priority Queues
Due: written part: 5pm February 2 (Thursday)
Homework 1
This is just the written part of hw1, due in 8 days. The
programming part of hw1 is not ready yet, it should probably be
available Friday, and due somewhat later.
Try to solve these problems, at most one page each, and turn in your
work on paper. If you cannot find me in class or my office, you may
slide your work under my office door (W426).
Suppose we have an input stream of
numbers,
and after reading the stream, we want to report the
largest
numbers. Also suppose
is relatively small compared to
:
. For both parts, describe how to solve the problem
using a binary heap. (For one of the parts, you'll also need the
linear-time heap construction method of Section 2.4, from the
discussion of heapsort.)
Solve the problem in
time, using
space.
Solve the problem in
time, using
space.
Remarks: the book solves one of these. In
both parts, ``space'' counts words of memory. A word is large enough
to store a single input number, or an integer at least as large as
. These two solutions constitute a ``trade-off'': we can solve the
problem in less time, if we use more space.
Consider a tree of height
constructed by the weighted quick-union algorithm (without path
compression). Argue that it has at least
nodes. Furthermore,
bound the number of its nodes at distance
from the root by the
binomial coefficient
. Finally, compute the average
depth (distance from the root) of a node in the worst case tree with
exactly
nodes.
Honor Policy
This assignment is governed by the Emory Honor Code, it should be your
own work. The programming part is governed by the department's
Statement of Policy on Computer Assignments.