Docsity

Computer Science 231 Assignment 2 - Recurrence Relations and Big O Notation, Assignments of Algorithms and Programming

Toggle sidebar
bg1
Assignment 2
Computer Science 231
Spring 2009
Due: Tuesday, February 17
Reading. CLRS Chapter 3, pages 41 -- 61; Appendix A, pages 1058 --1069.
CLR Chapters 2, 3, pages 20 -- 52
CLRS Exercise 2.3-3. Use mathematical induction to show that when n is an exact
power of 2, the solution of the recurrence
T(n)=2if n=2,
2T(n/ 2) +nif n=2k,k>1
is T(n) = n lg n.
Exercise 2.2.
a. Suppose algorithm A has worst-case running time O(n) and algorithm B has worst-
case running time O(n2 ). What can you say about the relative performance of the
algorithms?
b. Repeat part a for the worst-case running times Θ(n) and Θ(n2 ).
Exercise 2.3. Find two integer functions f(n) and g(n) such that f(n) is not O(g(n)) and
g(n) is not O(f(n)). (An integer function is a function that maps integers to integers.)
CLRS Problem 3-3a. You only need to hand in solutions to the 22 functions given
below, not the 30 as given in the text.
a. Rank the following function by order of growth; that is, find an arrangement g1, g2, . .
., g22 of the functions satisfying g1 = Ω(g2), g2 = Ω(g3), . . ., g21 = Ω(g22), Partition
your list into equivalence classes such that f(n) and g(n) are in the same class if and
only if f(n) = Θ(g(n)). One way to do this is to list functions f(n) and g(n) on the same
line if and only if f(n) = Θ(g(n)). List all other functions on separate lines in order of
their growth rates, fastest growth rates at the top of page.
(
2
)
lgn
n2 n! n3 lg2 n 22n
ln(ln n) n·2n ln n 1 2lg n 4lg n
(n+1)! ln n n 2n n lg n 22n+1
1
n 2n+1 n 3n
pf2

Partial preview of the text

Download Computer Science 231 Assignment 2 - Recurrence Relations and Big O Notation and more Assignments Algorithms and Programming in PDF only on Docsity!

Assignment 2

Computer Science 231 Spring 2009 Due: Tuesday, February 17 Reading. CLRS Chapter 3, pages 41 -- 61; Appendix A, pages 1058 --1069. CLR Chapters 2, 3, pages 20 -- 52 CLRS Exercise 2.3-3. Use mathematical induction to show that when n is an exact power of 2, the solution of the recurrence T ( n ) = 2 if n = 2, 2 T ( n / 2) + n if n = 2 k^ , k > 1

is T(n) = n lg n. Exercise 2.2. a. Suppose algorithm A has worst-case running time O( n ) and algorithm B has worst- case running time O( n^2 ). What can you say about the relative performance of the algorithms? b. Repeat part a for the worst-case running times Θ(n) and Θ( n^2 ). Exercise 2.3. Find two integer functions f(n) and g(n) such that f(n) is not O(g(n)) and g(n) is not O(f(n)). (An integer function is a function that maps integers to integers.) CLRS Problem 3-3a. You only need to hand in solutions to the 22 functions given below, not the 30 as given in the text. a. Rank the following function by order of growth; that is, find an arrangement g 1 , g 2 ,.. ., g 22 of the functions satisfying g 1 = Ω( g 2 ), g 2 = Ω( g 3 ),.. ., g 21 = Ω( g 22 ), Partition your list into equivalence classes such that f ( n ) and g ( n ) are in the same class if and only if f ( n ) = Θ( g ( n )). One way to do this is to list functions f ( n ) and g ( n ) on the same line if and only if f ( n ) = Θ( g ( n )). List all other functions on separate lines in order of their growth rates, fastest growth rates at the top of page. ( 2 ) lg n n^2 n! n^3 lg^2 n 22 n ln(ln n ) n ·2n^ ln n 1 2 lg^ n^ 4 lg^ n ( n +1)! ln n n 2 n^ n lg n 22 n + 1 n^2 n +1 (^) n 3 n

Assignment 2 Page 2 Computer Science 231 b. Give an example of a single nonnegative function f ( n ) such that for all functions gi ( n ) in part a, f ( n ) is neither O ( gi ( n )) nor Ω (gi ( n )). Hints. Here are a few relationships between notations that you may find useful.

  1. Notations f = O ( g ) and g = Ω (f) mean exactly the same thing.
  2. So do notations f = o ( g ) and g = ω (f).
  3. Whenever f = ω ( g ), then f = Ω (g) , and similarly, whenever f = o ( g ) then f = O(g). The converses of these statements do not always hold.
  4. f = Θ (g) if and only if f = O ( g ) and f = Ω (g).
  5. If f = o ( g ), then it is never the case that f = Ω (g).
  6. Similarly, if f = ω ( g ), then it is never the case that f = O ( g ). You should try to understand why each of the above statements is true.