This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Introduction to Algorithms September 30, 2005 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik D. Demaine and Charles E. Leiserson Handout 8 Problem Set 1 Solutions Problem 11. Asymptotic Notation For each of the following statements, decide whether it is always true , never true , or sometimes true for asymptotically nonnegative functions f and g . If it is always true or never true , explain why. If it is sometimes true , give one example for which it is true, and one for which it is false. (a) f ( n ) = O ( f ( n ) 2 ) Solution: Sometimes true : For f ( n ) = n it is true, while for f ( n ) = 1 /n it is not true. (The statement is always true for f ( n ) = (1) , and hence for most functions with which we will be working in this course, and in particular all time and space complexity functions). (b) f ( n ) + g ( n ) = (max ( f ( n ) , g ( n ))) Solution: Always true : max( f ( n ) , g ( n )) f ( n ) + g ( n ) 2 max( f ( n ) , g ( n )) . (c) f ( n ) + O ( f ( n )) = ( f ( n )) Solution: Always true : Consider f ( n ) + g ( n ) where g ( n ) = O ( f ( n )) and let c be a constant such that g ( n ) < cf ( n ) for large enough n . Then f ( n ) f ( n )+ g ( n ) (1 + c ) f ( n ) for large enough n . (d) f ( n ) = ( g ( n )) and f ( n ) = o ( g ( n )) (note the little o ) Solution: Never true : If f ( n ) = ( g ( n )) then there exists positive constant c and n such that for all n > n , cg ( n ) f ( n ) . But if f ( n ) = o ( g ( n )) , then for any positive constant c , there exists n o ( c ) such that for all n > n o ( c ) , f ( n ) < cg ( n ) . If f ( n ) = ( g ( n )) and f ( n ) = o ( g ( n )) , we would have that for n > max( n , n o ( c )) it should be that f ( n ) < c g ( n ) f ( n ) which cannot be. (e) f ( n ) negationslash = O ( g ( n )) and g ( n ) negationslash = O ( f ( n )) Solution: Sometimes true : For f ( n ) = 1 and g ( n ) = bardbl n sin( n ) bardbl it is true, while for any f ( n ) = O ( g ( n )) , e.g. f ( n ) = g ( n ) = 1 , it is not true. 2 Handout 8: Problem Set 1 Solutions Problem 12. Recurrences Give asymptotic upper and lower bounds for T ( n ) in each of the following recurrences. Assume that T ( n ) is constant for n 3 . Make your bounds as tight as possible, and justify your answers....
View Full
Document
 Spring '03
 PiotrIndyk
 Algorithms

Click to edit the document details