AlgorithmOne

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online