Dr. T.K. Ralphs
1. You are given information that the running time of algorithm A is
O
(
n
lg
n
) and that the
running time of algorithm B is
O
(
n
3
). What does this tell you about the relative performance
of A and B?
2. Show that
n
lg
n
∈
O
(
n
3
/
2
). Is it also true that
n
lg
n
∈
o
(
n
3
/
2
)?
3. For each pair of functions
f
and
g
, state whether
f
is
o
,
O
, Θ, Ω,
ω
of
g
(choose as many as
apply). Justify your assertion.
(a)
f
(
n
) = lg
n
,
g
(
n
) = ln
n
.
(b)
f
(
n
) =
n
1
/n
,
g
(
n
) = 1.
(c)
f
(
n
) =
n
lg
n
,
g
(
n
) =
n
.
4. Solve the following 3 recurrences. Assume that
T
(1) = 1.
(a)
T
(
n
) =
T
(
n

2) +
n/
2
(b)
T
(
n
) = 7
T
(
n/
3) +
n
2
(c)
T
(
n
) =
T
(
√
n
) + 1
5. Observe that the
while
loop of lines 57 of the insertion sort procedure on page 17 of CLRS
uses a linear search to scan through the sorted subarray
A
[1
. . . j

1] to ﬁnd the insertion
point. Since the subarray is already sorted, can we improve the worstcase running time by
using binary search to ﬁnd the insertion point? If so, what would be the improved worstcase
running time?
6. A
generalized queue
is a data structure that combines the functionality of a stack, in which
the item most recently added to the list is the next to be removed, with that of a standard
(FIFO) queue, in which the item least recently added to the list is the next to be removed.
In a basic generalized queue interface, the following operations are supported.
•
put
: add an item to the queue.
•
getMostRecent
: return a copy of the most recently added item and then delete it from
the queue.
•
getLeastRecent
: return a copy of the least recently added item and then delete it from
the queue.
•
empty
: indicate whether the queue is empty or not.
Note that we don’t have operations to look at items in the queue without deleting them.
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '07
 Ralphs
 Array

Click to edit the document details