2c03-review - 00029

2c03-review - 00029 - a function of n. Provide some

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

View Full Document Right Arrow Icon
3 n+1 > Clogn. Clearly n+1 > n, so it suffices to solve n > Clogn. From the question 1d above we conclude that Clogn 2C n 1/2 . So all we need is to solve n > 2Cn 1/2 , or equivalently n 1/2 > 4C 2 . This means n > 4C 2 implies n+1>Clogn, for all C>0. 3.[15] T 1 (n)=O(f(n)) means c 1 n 1 œ n $ n 1 T 1 (n) # c 1 f(n), and T 2 (n)=O(g(n)) means c 2 n 2 œ n $ n 2 T 2 (n) # c 2 g(n). Let n 3 =max(n 1 ,n 2 ), c 3 =max(c 1 ,c 2 ). a.[5] For every n $ n 3 we have: T 1 (n)+T 2 (n) # c 1 f(n)+c 2 g(n) # c 3 (f(n)+g(n)), so T 1 (n)+T 2 (n)=O(f(n)+g(n). b.[5] For every n $ n 3 we have: max(T 1 (n),T 2 (n)) # max(c 1 f(n),c 2 g(n)) # max(c 3 f(n),c 3 g(n)) # c 3 max(f(n),g(n)), so max(T 1 (n),T 2 (n)) = O(f(n),g(n)). c.[5] For every n $ n 3 we have: min(T 1 (n),T 2 (n)) # min(c 1 f(n),c 2 g(n)) # min(c 3 f(n),c 3 g(n)) # c 3 min(f(n),g(n)), so min(T 1 (n),T 2 (n)) = O(f(n),g(n)). 4.[30] Give, using A big O @ notation, the worst case running times of the following procedures as
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a function of n. Provide some calculation/justification. Just a formula only is not sufficient. a.[5] procedure P1(n:integer); var i,j,k : integer; begin for i:=1 to n-5 do for j:=1 to n/2 do begin C[i,j]:=0; for k:=1 to n do C[i,j]:=C[i,j] + A[i,k]*B[k,j] end end T(n) = n-5 i=1 T = n-5 i=1 ( n/2 j=1 T) = n-5 i=1 ( n/2 j=1 ( C + n k=1 O(1))) = n-5 i=1 ( n/2 j=1 ( C + O(n))) = n-5 i=1 ( n/2 j=1 O(n)) = n-5 i=1 (O(n 2 /4 +n/2)) = n-5 i=1 O(n 2 ) = O(n 2 (n-5)) = O(n 3 ) In other words we have 3 nested loops, each has complexity O(n), so O(n 3 )....
View Full Document

Ask a homework question - tutors are online