This preview shows pages 1–2. 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: CMPT 307  Data Structures and Algorithms: Solutions to PS 1 September 25, 2008 1. Asymptotics Rank the following functions by order of growth; that is, arrange the following 14 functions g 1 ,...,g 14 so that g 1 = O ( g 2 ) ,g 2 = O ( g 3 ) ,...,g 13 = O ( g 14 ). Here are the functions: n 2 , (log n )!, n !, log 2 n , 2 2 n , n 1 / log n , log log n , n log log n , 2 log n , 2 n , 2 2 log n , n , n log n , (3 / 2) n . Solution: n 1 / log n , log log n , log 2 n , 2 2 log n , 2 log n , n , n log n , n 2 , (log n )!, n log log n , (3 / 2) n , 2 n , n !, 2 2 n . Justification (for some of the cases): n 1 / log n = 2 log n/ log n = 2; (log n )! (log n ) log n = 2 (log log n )(log n ) = n log log n ; ( n !) ( n/ 2) n/ 2 2 n ; 2 2 log n < 2 log n = n ; 2 log n = n . 2. Recurrences Give asymptotic upper and lower bounds for T ( n ) in each of the follow ing recurrences. Assume that T ( n ) is constant for n 2. Make your bounds as tight as possible, and justify your answers: (a) T ( n ) = 2 T ( n/ 2) + n 3 . Solution: Expanding, we get T ( n ) = n 3 + 2( n/ 2) 3 + 4( n/ 4) 3 + 8( n/ 8) 3 + ... , with log n terms in the summation. Factoring out n 3 , we get T ( n ) = n 3 (1 + 1 / 4 + (1 / 4) 2 + (1 / 4) 3 + ... ). By the formula for geometric progression, we get 1 + 1 / 4 + (1 / 4) 2 + (1 / 4) 3 + 1 / (1 (1 / 4)) = 4 / 3. So, T ( n ) = ( n 3 ). (b) T ( n ) = 16 T ( n/ 4) + n 2 . Solution: Expanding, we get T ( n ) = n 2 + 16( n/ 4) 2 + 16 2 ( n/ 4 2 ) 2 +16 3 ( n/ 4 3 ) 2 + ... , with log 4 n terms in the summation. Factoring out n 2 , get T ( n ) = n 2 (1+16 / 16+16 2 / 16 2 +16 3 / 16 3 + ... ) = n 2 log 4 n = ( n 2 log n ). (c) T ( n ) = T ( n 1) + n . Solution: Expanding, get T ( n ) = n + ( n 1) + ( n 2) + ( n 3) + + 1, which is equal to n ( n + 1) / 2 = ( n 2 ) (by the formula for arithmetic progressions)....
View Full
Document
 Spring '09
 A.BULATOV
 Algorithms, Data Structures

Click to edit the document details