AlgorithmOne

# AlgorithmOne - Analysis of Algorithms Fall 2004 Home Work 1...

This preview shows pages 1–2. Sign up to view the full content.

Analysis of Algorithms Fall 2004 Home Work 1 Due: Tuesday Oct 5 Thursday Sep 30 in class Points 20 Set up the recurrence equations for time complexity of the following four algorithms and solve them for the usual theta function (asymptotic complexity). Do not bother on what do the algorithms do. Submit hard copy. Algorithm One (int array A[], int start, int end) begin if (start = = end) then return A[start] else begin int mid = (start+end)/2; if (A[start] < A[mid]}) then One (A, start, mid) else One(A, mid+1, start); for i = start through end do for j = i through end do A[i] = A[j]-10; end; return; end algorithm. Overhead from the for loops: Sum(I=1,n) Sum (j=I,n) c = c*Sum(I=1,n) [n-I+1] = c*[(n-1+1) + (n-2+1) +(n-3+1) + . . . +(n-n+1)] = c*[n+ (n-1) + (n-2) + . . . +1] = c*n(n+1)/2 = (c/2)*(n^2 + n) = Theta(n^2) Recurrence equation: T(n) = T(n/2) + k*(n^2) Master eq: [a=1, b=2, I=2; a<b^i] T(n) = Theta(n^2) Algorithm Two (int array A[], int start, int end) begin if (start = = end) then return A[start] else

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.

{[ snackBarMessage ]}

### Page1 / 3

AlgorithmOne - Analysis of Algorithms Fall 2004 Home Work 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online