{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

2c03-review - 00092

# 2c03-review - 00092 - end T(n = Σ 10n i=5n T’ = Σ 10n...

This preview shows page 1. Sign up to view the full content.

5 for j:=3005 to 2*n*n do begin C[i,j]:=0; for k:=n/5 to 3*n do C[i,j]:=C[i,j]*A[i,k]; for k:=n to n*n do C[i,j]:=C[i,j] + A[i,k]*B[k,j]; for k:=1 to n/2 do C[i,j]:=C[i,j]*A[i,k]; end end else begin C[i,j]:=A[i,j]; for k:=n*n/3 to n*n/2 do C[i,j]:=C[i,j]*A[i,k]; end T(n) = Σ n i=1 T1(n) = Σ n i=1 (T2(n) + T3(n)) = Σ n i=1 ( Σ 2n*n j=3005 T4(n) + Σ n*n/2 k=n*n/3 O(1)) = Σ n i=1 ( Σ 2n*n j=3005 ( Σ 3n k=n/5 O(1) + Σ n*n k=n O(1) + Σ n/2 k=1 O(1)) + O(n 2 )) = Σ n i=1 ( Σ 2n*n j=3005 (O(n 2 )) + O(n 2 )) = Σ n i=1 (O(n 4 ) + O(n 2 )) = O(n 5 ) b.[5] procedure P2(n:integer); var i,j,k,l : integer; begin for i:=5*n to 10*n do label for j:=i-1 to 200000000000000000 do for k:=j to n*n do for l:=i to n*j {some statement requiring O(1) time}
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: end T(n) = Σ 10n i=5n T’ = Σ 10n i=5n ( Σ 200000000000000000 j=i-1 T’’) When n is sufficiently large such that 5n 200000000000000000, the labeled for loop does nothing but a comparison which cost constant time. Therefore, T(n) = Σ 10n i=5n (O(1)) = O(n) c.[15] function F(n:integer):integer; begin if n<=1 then return(1) else return(2*F(n-1)+3*F(n-3)) end T(n) = if n ≤ 1 then C 1 else C + T(n - 1) +T(n - 3) Define T 1 (n) = if n ≤ 1 then C 1 else C + 2*T 1 (n - 3), and T 2 (n) = if n ≤ 1 then C 1 else C + 2*T 2 (n - 1). Note that T 1 (n)<T(n)< T 2 (n)...
View Full Document

{[ snackBarMessage ]}