Docsity

Asymptotic Notation Midterm 1 Review Problems, Study notes of Computer Science

Toggle sidebar
bg1
CMPS 101
Midterm 1 Review Problems
1. Let )(nf and )(ng be asymptotically non-negative functions which are defined on the positive integers.
a. State the definition of ))(()( ngOnf
=
.
b. State the definition of ))(()( ngnf
ω
=
2. State whether the following assertions are true or false. If any statements are false, give a related
statement which is true.
a. ))(()( ngOnf
=
implies ))(()( ngonf
=
.
b. ))(()( ngOnf
=
if and only if ))(()( nfng
Ω
=
.
c. ))(()( ngnf
Θ
=
if and only if Lngnf
n=
∞→ ))(/)((lim , where
∞
<
<
L0.
3. Prove that ))()(())(())(( ngnfngnf
⋅
Θ
=
Θ
⋅
Θ
. In other words, if ))(()(
1nfnh Θ= and ))(()(
2ngnh Θ= ,
then ))()(()()( 21 ngnfnhnh ⋅Θ=⋅ .
4. Use limits to prove the following (these are some of the exercises at the end of the asymptotic growth
rates handout):
a. If )(nP is a polynomial of degree 0
≥
k, then )()( k
nnP Θ= .
b. For any positive real numbers
α
and
: )(
βα
non = iff
α
<
, )(
βα
nn Θ= iff
α
=
, and
)(
βα ω
nn = iff
α
>
.
c. For any positive real numbers a and b: )( nn boa = iff ba
<
, )( nn ba Θ= iff ba
=
, and )( nn ba
ω
=
iff ba
>
.
d. ))(())(()( nfnfonf
Θ
=
+
.
5. Use Stirling’s formula:
( )
)/1(12! n
e
n
nn
n
Θ+⋅
⋅=
π
, to prove that )log()!log( nnn
Θ
=
.
6. Use Stirling’s formula to prove that
Θ=
n
n
nn
4
2.
7. Consider the following sketch of an algorithm called ProcessArray which performs some unspecified
operation on a subarray ][ rpA .
ProcessArray(A, p, r) (Preconditions: 1
≥
p and ][ Alengthr
≤
)
1. do something which takes constant time.
2. if
r
p
<
3.
+
←2
rp
q
4. ProcessArray(A, p, q)
5. ProcessArray(A, q+1, r)
Write a recurrence which gives the running time )(nT of this algorithm, when called on the full array
]1[ nA . Give a tight asymptotic solution to this recurrence.
pf2

Partial preview of the text

Download Asymptotic Notation Midterm 1 Review Problems and more Study notes Computer Science in PDF only on Docsity!

CMPS 101

Midterm 1 Review Problems

  1. Let f ( n )and g ( n ) be asymptotically non-negative functions which are defined on the positive integers.

a. State the definition of f ( n )= O ( g ( n )).

b. State the definition of f ( n )= ω( g ( n ))

  1. State whether the following assertions are true or false. If any statements are false, give a related statement which is true. a. f ( n )= O ( g ( n ))implies f ( n )= o ( g ( n )). b. f ( n )= O ( g ( n ))if and only if g ( n )= Ω( f ( n )). c. f ( n )= Θ( g ( n ))if and only if f n gn L n

→ ∞ lim ( ( )/ ( )) , where 0 < L <∞.

  1. Prove that Θ( f ( n ))⋅Θ( g ( n ))=Θ( f ( n )⋅ g ( n )). In other words, if h 1 (^) ( n )= Θ( f ( n )) and h 2 (^) ( n )= Θ( g ( n )),

then h 1 (^) ( n )⋅ h 2 ( n )=Θ( f ( n )⋅ g ( n )).

  1. Use limits to prove the following (these are some of the exercises at the end of the asymptotic growth rates handout): a. If P ( n )is a polynomial of degree k ≥ 0 , then P ( n )= Θ( nk ).

b. For any positive real numbers α and β : n α^ = o ( n^ β) iff α < β, n α^ = Θ( n^ β) iff α = β, and

n α^ = ω ( n^ β)iff α > β.

c. For any positive real numbers a and b : a n^ = o ( bn ) iff a < b , a n^ = Θ( bn )iff a = b , and an^ = ω( bn )

iff a > b. d. f ( n )+ o ( f ( n ))=Θ( f ( n )).

5. Use Stirling’s formula:! 2 ( 1 ( 1 / n ))

e

n n n

n  ⋅ +^ Θ 

= π ⋅ , to prove that log( n! )= Θ( n log n ).

  1. Use Stirling’s formula to prove that (^)  

=^ Θ

n n

2 n (^) 4 n .

  1. Consider the following sketch of an algorithm called ProcessArray which performs some unspecified operation on a subarray A [ p  r ].

ProcessArray(A, p, r) (Preconditions: p ≥ 1 and r ≤ length [ A ])

  1. do something which takes constant time.
  2. if p < r
  3. (^)  

p r q

  1. ProcessArray(A, p, q)
  2. ProcessArray(A, q+1, r)

Write a recurrence which gives the running time T ( n ) of this algorithm, when called on the full array A [ 1  n ]. Give a tight asymptotic solution to this recurrence.

  1. Consider the following algorithm which does nothing but waste time:

WasteTime(n) (pre: n ≥ 1 )

  1. if n > 1
  2. for i ← 1 to n^3
  3. waste a constant amount of time
  4. for i ← 1 to 7

5. WasteTime ( n / 2 )

  1. waste a constant amount of time

Write a recurrence which gives the running time T ( n ) of this algorithm. Give a tight asymptotic solution to this recurrence.

  1. Use the Master Theorem to find tight asymptotic solutions for the following recurrences.

a. T ( n )= 2 T ( n / 4 )+ n b. T ( n )= 7 T ( n / 3 )+ n^2

10. Define T ( n ) by: T ( 1 )= 0 and T ( n )= T ( n / 2 ) + 1 for n ≥ 2. Use the iteration method to show

T ( n )= lg( n ) for all n , whence T ( n )= Θ(log( n )).

  1. Define T ( n )by the recurrence

 (^ )

T n n

T n 3 / 3

n

n

n

Show that there exists a c > 0 such that T ( n )≤ cn lg n for all n ≥ 3. Prove this using induction on n ( not the Master Theorem.) (Note: this problem is a watered down substitution method, i.e. I'm giving you n 0 (namely 3), and you must determine c .)

  1. Prove that all trees on n vertices have n − 1 edges. Do this by (a) induction on the number of vertices, and (b) by induction on the number of edges.