CSE310 HW02, Solution and Grading Keys
1. (15 pt) Suppose we have two algorithms
A
1 and
A
2 for solving the same problem. Let
T
1
(
n
) be
the worst case time complexity of Algorithm
A
1 and
T
2
(
n
) be the worst case time complexity
of Algorithm
A
2. We know that
T
1
(1) = 1 and
T
1
(
n
) = 7
·
T
1
(
n/
2)+
f
(
n
), where
f
(
n
) = Θ(
n
2
).
We also know that
T
2
(1) = 1 and
T
2
(
n
) = 63
·
T
2
(
n/
4) + 30
·
n
2
.
•
Use the master method to decide
T
1
(
n
).
Follow all the steps as illustrated in class
(
a, b,
log
b
a
, etc).
a
= 7,
b
= 2, log
b
a
= 2
.
80735.
For
∈
(0
,
0
.
80735), we have
f
(
n
) =
O
(
n
2
.
80735

).
Therefore we have case1 in the Master method.
As a result,
T
1
(
n
) = Θ(
n
2
.
80735
).
Grading:
+1 pt for
a
;
+1 pt for
b
;
+1 pt for log
b
a
;
+1 pt for the correct case;
+1 pt for the correct answer.
•
Use the master method to decide
T
2
(
n
).
Follow all the steps as illustrated in class
(
a, b,
log
b
a
, etc).
a
= 63,
b
= 4, log
b
a
= 2
.
98864.
For
∈
(0
,
0
.
98864), we have
f
(
n
) =
O
(
n
2
.
98864

).
Therefore we have case1 in the Master method.
As a result,
T
2
(
n
) = Θ(
n
2
.
98864
).
Grading:
+1 pt for
a
;
+1 pt for
b
;
+1 pt for log
b
a
;
+1 pt for the right case;
+1 pt for the right answer.
•
Which algorithm is faster? Why?
Since
T
1
(
n
) =
O
(
T
2
(
n
)), but
T
2
(
n
)
6
=
O
(
T
1
(
n
)), we conclude that A1 is faster.
Grading:
+3 pts for the answer;
+2 pts for the justification.
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 '08
 Davulcu,H
 Algorithms, Data Structures, Insertion Sort

Click to edit the document details