This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 22 C : 031 Algorithms Midterm This is a closed book exam. You have an hour and fifteen minutes. 1. Give an asymptotically tight bound on the worst case running time of the following algorithm as a function of n , the number of elements in input array A and output array C . (Express runing time as Θ( f ( n )) for some appropriate f .) (2 points) For i from 1 to n do C[i] := 0 endfor For i from 1 to n do For j from i to n do C[i] := C[i] + A[j] endfor endfor Return C 2. Give an asymptotic upper bound on the worst case running time of the following algorithm as a function of n , the number of elements in input array A and output array C . (Express running time as O ( f ( n )) for some appropriate f .) Pick as good an f as you can. (3 points) For i from 1 to n do C[i] := 0 endfor For i from 1 to n do j:= i While j is less than or equal to n do C[i] := C[i] + A[j] j:= 2 * j endwhile endfor Return C 3. In each of the following cases, say whether f ( n ) is O ( g ( n )) and whether f ( n ) is...
View
Full
Document
This note was uploaded on 11/26/2009 for the course CIS 502 taught by Professor Naver during the Spring '09 term at National Tsing Hua University, China.
 Spring '09
 Naver
 Algorithms

Click to edit the document details