This preview shows pages 1–2. Sign up to view the full content.
Q1.
You are given recursive CombineSort procedure that sorts input sequence A={
a
1,
a
2…
a
n}. Find its recurrence relation T(n) and use it to calculate worst case
complexity of this algorithm. (Note: Combine procedure has
cn
worst time
complexity).
Start = 1;
Finish = n;
BEGIN
CombineSor
t(A, Start, Finish)
IF (Start < Finish) THEN
Middle=(Start + Finish)/2;
CombineSor
t(A, Start, Middle);
CombineSor
t(A, Middle+1, Finish);
Combin
e(A, Start, Middle, Finish);
END IF
END BEGIN
Answer:
Unless you already got it, it is nothing but MergeSort.
Recurrence relation is
T(n) = 2T(n/2) + cn; n > 1
T(n) = a; n = 1
This relation can be solved by substitutions
T(n) = 2(2T(n/4)+cn/2)+cn = 4(2T(n/8)+cn/4)+2cn = … 2
k
T(1)+kcn = an+cn log n
Hence T(n) = O(n log n)
Q2.
Water flows into Hoover dam at a variable rate throughout every month (i.e., 30
days: the tidal cycle) and water is released at a regular interval (once every month).
You have the detailed water level data for a period of 30 consecutive days (not
necessarily a calendar month, and not necessarily starting or ending with the time of
releasing the water).
Give an efficient algorithm to find out exactly when the water was released. (Assume
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 11/30/2011 for the course COT 5405 taught by Professor Ungor during the Fall '08 term at University of Florida.
 Fall '08
 UNGOR
 Algorithms, Sort

Click to edit the document details