This preview shows pages 1–2. Sign up to view the full content.
CSE 5211
Fall 2007
Exam 1
Points: 50
Time: 85 min
Answer SKETCHES.
1.
For two given positive integers
a
, and
n
, the value
na
may be computed naively by
adding
a
with itself
n
times, i.e.,
Θ
(n) time. Write a
divideandconquer
algorithm for the
same purpose. Find your algorithm’s asymptotic timecomplexity by setting up the
corresponding recurrence equation and then solving it (use Master’s theorem).
Recursively add one half and multiply the result with 2. Recursion terminates with n==1.
T(n) = T(n/2) +1. T(n) = O(log n). Presumption: you can multiply with 2 in constant
time.
2a.
What is the
Order
(BigO) of the variable
count
in terms of
n
after the following
algorithmfragment is executed?
[5]
(1) count = 0;
(2) For
i
= 1 through
n
do
(3)
For
p
= 1 through 3
do
(5)
For
k =
1 through
i
do
(4)
count = count +1;
end for loops;
O(n^2)
2b.
What is the asymptotic timecomplexity of the following algorithm fragment? [5]
(0) int
count
:= 0;
(1) For
i
=1 through 5
do
(2)
For
p
= 1 through
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.
This note was uploaded on 02/10/2012 for the course CSE 5211 taught by Professor Dmitra during the Spring '12 term at FIT.
 Spring '12
 Dmitra
 Algorithms

Click to edit the document details