(d) A priority queue is a queue in which elements are enqueued in order of their priority, true or
false?
(e) Suppose we decide to change our model of computation (step-counting) by counting instructions
that involve the creation of an array
new int[n]
as taking 10
n
steps.
In this new model, a
program can have a different asymptotic complexity than in the original model, true or false?
(f) In a binary min-heap with at least three elements the largest element is always in the right
subtree of the root: true or false?
(g) Suppose that
f
(
n
) is a function defined only for integers
n
≥
1 and that
f
(
n
)
is O
(1). Then,
there exists a constant
c
0
such that
f
(
n
)
≤
c
0
for all
n
≥
1, true or false?
6. A binary heap contains the keys 1
,
2
, . . . ,
10
,
11.
If we traverse it in postorder we list the keys as
follows: 10
,
8
,
7
,
5
,
4
,
3
,
2
,
11
,
9
,
6
,
1. Draw the heap.
7. After a
removeMin
operation that returns the key
a
, a binary min-heap looks like this (the keys are
ordered alphabetically):
b
/ \
/
\
/
\
c
f
/ \
/ \
/
\
/
\
g
d
k
i
/ \
/
j
h e
Draw
two different
trees that could have been what the heap looked like
before
the
removeMin
operation.
8. Consider a binary heap of height
h
and let
L
be the number of nodes at depth
h
in this tree. Assuming
that the tree has 1000 nodes, calculate
h
and
L
.
9. (15 points) In this problem you NOT allowed to use any of the theorems about Big-Oh stated in the
lecture slides, the textbook, or the lab writeups.
Your proof should rely only on the definition of
Big-Oh.
Prove that
n
2
+3
n
√
n
is
O
(
n
√
n
).
10. (15 points)
Provide counterexamples for each of the following two
false
statements. You only need to give the
counterexample, you
don’t need to prove
that it works. (As usual in this kind of problem,
f
(
n
) and
g
(
n
) map nonnegative reals to strictly positive reals.)
(a) There is
no
f
(
n
) such that
f
(
n
) is
O
(log
√
n
) and
f
(
n
) is Ω(log
n
2
).
5