This preview shows pages 1–2. Sign up to view the full content.
Advanced Analysis of Algorithms  Homework I (Solutions)
K. Subramani
LCSEE,
West Virginia University,
Morgantown, WV
{
ksmani@csee.wvu.edu
}
1
Problems
1. Solve the following recurrences:
(a)
T
(
n
) =
T
(
√
n
) + 1
.
(b)
T
(
n
) = 4
T
(
n
2
) +
n
2
·
log
n
.
Solution:
(a) Substitute
n
= 2
k
. The recurrence then becomes:
T
(2
k
) =
T
(2
k
2
) + 1
.
Use
G
(
k
)
to denote
T
(2
k
)
. Accordingly, the recurrence can be written as:
G
(
k
) =
G
(
k
2
) + 1
.
Using any of the methods discussed in class or [CLRS01], it can be shown that
G
(
k
) = log
k
.
Thus,
T
(2
k
) = log
k
, from which it follows that
T
(
n
) = log log
n
.
(b) We can directly use the Master Theorem. In this case,
a
= 4
,
b
= 2
and
f
(
n
) =
n
2
log
n
. Thus,
f
(
n
)
∈
Θ(
n
log
b
a
·
log
1
n
)
, from which it follows that
T
(
n
) = Θ(
n
2
log
2
n
)
.
2
2. Professor Krustowski claims to have discovered a new sorting algorithm. Given an array
A
of
n
numbers, his
algorithm breaks the array into
3
equal parts of size
n
3
, viz., the ﬁrst third, the middle third and the bottom third. It
then recursively sorts the ﬁrst twothirds of the array, the bottom twothirds of the array and ﬁnally the ﬁrst twothirds
of the array again. Using mathematical induction, prove that the Professor has indeed discovered a correct sorting
algorithm. You may assume the following: The input size
n
is always some multiple of
3
; additionally, the algorithm
sorts by bruteforce, when
n
is exactly
3
.
Solution:
As per the speciﬁcations, the algorithm works correctly, when
n
≤
3
.
Assume that the algorithm works correctly, as long as
1
≤
n
≤
k
, where
k >
3
.
Now consider the case where the array
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

Click to edit the document details