Work Note 2, DM803, fall 2016
Exercises September 12
-
Show that there is at most a logarithmic number of nodes on the
right-most path in a leftist heap with n element.
Hint: Show that a node of rank r has exponentially
many nodes in its subtree. Then consider how ranks behave
on the right-most path.
-
Show that two standard heaps (as known from DM507)
with 2p-1 elements each plus one extra element
x can be combined into one heap in time O(p).
Show that a standard heap can be build out of n=2p-1
elements in time O(n) by a bottom-up application of the
result above.
Given n elements, how can a leftist heap be constructed in
time O(n)?
-
How can the operations decreasekey, delete, and
update be implemented to run in time O(log n)
for leftist heaps? It is assumed that you are given a
reference to the element and you may introduce additional
references in the structure.
Hint: Some operations can be reduced to others.
-
[CLRS09] 17.3-3, 17.3-6, 17.3-7.
Hint: in 17.3-7, you may assume that the median of n elements
can be found in time O(n).
-
Come up with an implementation of a queue (not priority queue), where,
in addition to the usual operations enqueue and dequeue,
there is an operation findmin that reports the minimum
element in the queue (assuming we have a total ordering on the elements).
All operations should be OA(1).
-
Show the claim from the lecture that there are at most
a logarithmic number of light nodes on the right-most
path of a skew heap.
-
For skew heaps, what if we define heavy as
|Tr(x)| ≥ ¾ |Tx|?
Or |Tr(x)| ≥ ¼ |Tx|?
How does that affect the analysis?
-
One can probably easily imagine scenarios where leftist heaps
are preferable to skew heaps, but what if you are just interested
in the final result of running an algorithm on n elements
and during the course of the algorithm, one has to merge
priority queues n times. Which priority queue implementation
do you think would be best?
-
Here is an alternative to leftist heaps: As for leftist heaps, we
consider binary heap-ordered trees. However, instead of rank, each
node has a size attribute, storing the size of the subtree
in which it is a root. Just as for leftist heaps, we define meld,
and then all other operations follow from that.
The meld operation is defined as follows. Assume that we want to meld
X and Y, and assume that X has the smallest key
k in the root (otherwise we just switch the two arguments)
and that its two subtrees are
Xleft and Xright.
Now sort the trees Xleft, Xright,
and Y in non-decreasing order of size
and name them A, B, and C,
i.e., A.size ≤ B.size ≤ C.size.
Make a node that has k in the root and the two subtrees
meld(A,B) and C.
Consider correctness and complexity.
Lecture September 15
Announcements
-
In general, the exercises are not ordered according to difficulty.
Thus, harder exercises may be followed by easier ones. In preparation for
exercis classes, go through all of them, think about them, and
try to solve them. But if you don't manage to solve an exercise, just
proceed to the next one. It's important to go through the process
of problem solving, thereby fully understanding the problems and where
it becomes difficult before seeing the answers in class.
Last modified: Tue Sep 6 13:50:05 CEST 2016
Kim Skak Larsen
(kslarsen@imada.sdu.dk)