Tutorial Exercise (Recurrences)

advertisement
Tutorial Exercise (Recurrences)
CS3381 Design and Analysis of Algorithms
Helena Wong, 2001
1. Describe how Merge-Sort follows the Divide-and-Conquer paradigm.
2. To prove the correctness of the Merge(A,p,q,r) procedure. Let’s state the loop invariant as
“At the start of each iteration of the for loop of lines 12-17, the subarray A[p..k-1] contains
the k-p smallest elements of L[1..n1+1] and R[1..n2+1], in sorted order. Moreover, L[I] and
R[j] are the smallest elements of their arrays that have not been copied back to A.”
Complete the prove by showing the 3 properties of the invariant.
3. Use a recursion tree to determine a good asymptotic upper bound on the recurrence:
T(n) =
3T(n/2)+n
1
if n>1
if n=1
4. Given T(n)=T(n/2)+T(n/2)+1.
We guess that it is O(n). However, it is difficult to prove that “T(n)  cn for some positive constant
c”, because by substitution (T(n/2) and T(n/2) are true), T(n)  c(n/2)+c(n/2)+1=cn+1, that
does not imply T(n)  cn.
Try to prove that T(n) is O(n) by showing T(n)  cn -b, for some positive constants c and b.
Note: Normally, if not specified, we assume T(1)=1.
5. Use the master method to give tight asymptotic bounds for the following recurrences:
a. T(n) = 4T(n/2)+n
b. T(n) = 4T(n/2)+n2
c. T(n) = 4T(n/2)+n3
Download