This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: COMP 271 Design and Analysis of Algorithms 2004 Fall Semester Solutions to Question Bank Number 1 (Selected Problems) Answer 1. The proof is by induction on n , the limit of the summation. For the basis case we consider the smallest legal value of n , namely 1. We have 1 summationdisplay i =1 i ( i − 1) = 0 = 1(1 − 1)(1 + 1) 3 , as desired. For the induction step, we will assume that the formula holds for all the values 1 , 2 , . . ., n − 1, then show that it holds for n . The standard method is to get rid of the last term of the sum, use the induction hypothesis to apply the formula to the the sum consisting of the first n − 1 terms, and then add the last term back in again and simplify. n summationdisplay i =1 i ( i − 1) = parenleftBigg n 1 summationdisplay i =1 i ( i − 1) parenrightBigg + n ( n − 1) = ( n − 1)(( n − 1) − 1)(( n − 1) + 1) 3 + n ( n − 1) (by ind. hyp.) = ( n − 1)( n − 2) n 3 + n ( n − 1) = ( n − 2) n ( n − 1) + 3 n ( n − 1) 3 = ( n − 2 + 3) n ( n − 1) 3 = n ( n − 1)( n + 1) 3 , as desired. Answer 2. (a) True. Since T 1 ( n ) = O ( f ( n )) and T 2 ( n ) = O ( f ( n )), it follows from the def inition that there exist constants c 1 , c 2 > 0 and positive integers n 1 , n 2 such that T 1 ( n ) ≤ c 1 f ( n ) for n ≥ n 1 and T 2 ( n ) ≤ c 2 f ( n ) for n ≥ n 2 . This implies that, T 1 ( n ) + T 2 ( n ) ≤ ( c 1 + c 2 ) f ( n ) for n ≥ max( n 1 , n 2 ). Thus, T 1 ( n ) + T 2 ( n ) = O ( f ( n )). (b) False. For a counterexample to the claim, let T 1 ( n ) = n 2 , T 2 ( n ) = n, f ( n ) = n 2 . Then T 1 ( n ) = O ( f ( n )) and T 2 ( n ) = O ( f ( n )) but T 1 ( n ) T 2 ( n ) = n negationslash = O (1). (c) False. We can use the same counterexample as in part (b). Note that T 1 ( n ) negationslash = O ( T 2 ( n )) Answer 3. A Relation: B (a) n 3 + n log n Ω , Θ , O n 3 + n 2 log n (b) log √ n Ω √ log n (c) n log 3 n Ω , Θ , O n log 4 n (d) 2 n Ω 2 n/ 2 (e) log(2 n ) Ω , Θ , O log(3 n ) Notes: (a) Both are Θ( n 3 ), the lower order terms can be ignored. Note that if A ( n ) = Θ( B ( n )), then automatically A ( n ) = O ( B ( n )) and A ( n ) = Ω( B ( n ))....
View
Full
Document
This note was uploaded on 10/18/2009 for the course COMP 271 taught by Professor Arya during the Spring '07 term at HKUST.
 Spring '07
 ARYA
 Algorithms

Click to edit the document details