Assignement 2
COSC 3P03, Algorithms
Winter, 2011
Due: Feb. 18, Friday, noon.
1. (10) The running time of an algorithm A is described by
t
(
n
) = 7
t
(
n/
2) +
n
2
. A competing
algorithm B has a running time
T
(
n
) =
aT
(
n/
4) +
n
2
. What is the largest integer value for
a
such that B is asymptotically faster than A?
For algorithm
A
, by the masters method,
t
(
n
) =
O
(
n
log
2
7
)
.
For
A
p
, we can assume that
a >
16 since if
a
= 16, by masters method,
T
(
n
) = Θ(
n
2
log
n
)
,
which is already better than
t
(
n
). For
a >
16, since
n
2
=
O
(
n
log
4
a

e
) for some
e >
0, the
solution for
T
(
n
) is (Case 1)
T
(
n
) =
O
(
n
log
4
a
)
.
To ±nd the largest
a
such that log
4
a <
log
2
7, namely, log
2
a/
log
2
4
<
log
2
7, we have log
2
a <
log
2
7
2
, i.e.,
a <
49, therefore,
a
= 48.
2. (20) Explain why we would still have a lineartime selection algorithm if elements are divided
into groups of
k
elements, for
k
= 7, 9, 11, .
..? Show that if elements are divided into groups
of 3, then we have an Ω(
n
log
n
) algorithm.
If the group size is 7, the recurrence becomes
t
(
n
) =
t
(
n/
7) +
t
(3
n/
4) +
c
p
n
which has a solution
t
(
n
) =
O
(
n
) (see A1.Q8, since 1
/
7 + 3
/
4
<
1, or by a proof similar to
the one we did when the size is 5 in class). So yes, we will still have a lineartime selction
algorithm if the group size is 7 (by the same reasoning, OK if it is 9, 11, .
.....
).
When the group size is 3, we would have
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.
 Fall '11
 Qiu

Click to edit the document details