This preview shows pages 1–2. Sign up to view the full content.
CS38, Spring 2009
Introduction to Algorithms
Prof. Alexei Kitaev
Problem set #1
Due Friday April 10, 2009 at 5pm
in the box in the VLSI lab.
Problems
1. Exercises:
a) (4 points)
Sort the following functions in order of their asymptotic growth (i.e., the
O
relation
means “
≤
”, the Ωrelation means ‘
≥
”, and Θ means “=”:
n,
n
log
n,
(log
2
n
)
n
,
(ln
n
)
n
,n
ln
n
,
2
n
!
,
±
2
n
n
²
,
ln(
n
!)
,
ln
±
2
n
n
²
.
You may use the Stirling approximation:
n
!
≈
√
2
πn
(
n/e
)
n
.
b) (3 points)
Solve the recurrence
T
(
n
)=3
T
(
n/
2) +
O
(
n
2
).
c) (3 points)
Solve the recurrence
T
(
n
)=
T
(
n/
3) +
T
(2
n/
3) +
O
(
n
).
2. CLRS problem 22 (Correctness of bubblesort):
a) (1 point)
b) (4 points)
c) (4 points)
d) (1 point)
3. Let a sequence
S
=(
x
1
,...,x
n
) be sorted. A corresponding sequence
A
x
f
(1)
f
(
n
)
)
is called “
k
almost sorted” if

f
(
i
)
−
i
≤
k
for all
i
=1
,...,n
.
a) (10 points)
Find an algorithm that sorts a
k
almost sorted sequence in time
O
(
n
log
k
). You
don’t need to reason using pseudocode; just give a higherlevel correctness proof.
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 '10
 Algorithms, Sort

Click to edit the document details