You are on page 1of 3

The University of Newcastle School of Electrical Engineering and Computer Science

COMP2230 Introduction to Algorithmics

Tutorial Week 4
16 August 2010

Tutorial
1. Find for the following functions i. 6n3 + 12n + 1 ii. (n + 1)(n + 3) /(n + 2) 2. Find for the number of times the statement x=x+1 is executed. i. for i=1 to n

for j=1 to i for k=1 to j x=x+1

ii. i=2
while (i < n){ i=i*i x=x+1}

3. Prove the following: i. n! = O(nn ) ii. i=1n i lg i = (n2 lg n) 4. Use iteration to solve the following recurrence relations: i. an = an-1 + 3, n > 1; a1 = 2 ii. an = 2an-1 , n > 0; a0 = 1 5. True or false? i. n2 = O(n3 ) ii. n2 = (n3 ) iii. n2 = (n3 )

6. Arrange the following functions in ascending order in their growth rate. That is, if a function g(n) comes after function f(n) then f(n) = O(g(n)). Prove your answers. n2 , n3 , 100n2 , n lg n, 2n

Workshop
7. Find for the following functions i. (6n + 1) 2 ii. 3n2 + 2n lg n 8. Find for the number of times the statement x=x+1 is executed. i. for i=1 to 2n
x=x+1

ii. for i=1 to n


for j=1 to i for k=1 to i x=x+1

9. Prove the following: i. 2n = O(n!) ii. lg (nk + c) = (lg n), for every fixed k > 0 and c > 0 10. Use iteration to solve the following recurrence relations: i. an = 2an-1 + 1, n > 1; a1 = 1 ii. an = 2n an-1 , n > 0; a0 = 1 11. True or false? i. 2n = O(2n+1 ) ii. 2n = (2n+1 )

iii. 2n = (2n+1 )

12. Arrange the following functions in ascending order in their growth rate. That is, if a function g(n) comes after function f(n) then f(n) = O(g(n)). Prove your answers. 10n , n1/3 , nn , lg n, 2^((lg n)1/2) Hint: Look at logs of functions

More Exercises
13. Prove that Hn = i=1 (1/i) = (log n). (Hint: In the previous tutorial you proved that 1/n lg (n+1) lg n < 2/n .)
n

14.

Find for the following functions 2 + 4 + 6 + + 2n

15.

Find for the number of times the statement x=x+1 is executed.


j=n while (j 1){ for i=1 to j x=x+1 j=j/3}

16. 17.

Prove the following: 1k + 2k + + nk = (nk+1 ) Use iteration to solve the following recurrence relations: an = 2 + i=1n-1 ai, n > 1; a1 = 1

18. 19.

Prove that log (n!) = (n log n). True or false? i. n! = O((n+1)!) ii. n! = ((n+1)!) iii. n! = ((n+1)!)

20. Arrange the following functions in ascending order in their growth rate. That is, if a function g(n) comes after function f(n) then f(n) = O(g(n)). Prove your answers. n2.5 , (2n)1/2 , n+10, 10 n , 100n , n 2 lg n

You might also like