Docsity

Asymptotic Notation: O-, Ω-, Θ-notation and Recurrences, Assignments of Computer science

Toggle sidebar
bg1
September 12, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.1
Introduction to Algorithms
6.046J/18.401J
LECTURE 2
Asymptotic Notation
•O-, Ω-, and Θ-notation
Recurrences
•Substitution method
•Iterating the recurrence
•Recursion tree
•Master method
Prof. Erik Demaine
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39

Partial preview of the text

Download Asymptotic Notation: O-, Ω-, Θ-notation and Recurrences and more Assignments Computer science in PDF only on Docsity!

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

Introduction to Algorithms

6.046J/18.401J^ LECTURE

Asymptotic Notation •^ O -,^ Ω-, and

Θ-notation Recurrences • Substitution method• Iterating the recurrence• Recursion tree• Master method Prof. Erik Demaine

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

Asymptotic notation O -notation (upper bounds): We write^

f ( n ) =^ O ( g

( n )) if there exist constants

c^ > 0,^ n^0

0 such that 0^ ≤^ f (

n )^ ≤^ cg ( n ) for all

n^ ≥^ n.^0 We write^

f ( n ) =^ O ( g

( n )) if there exist constants

c^ > 0,^ n^0

0 such that 0^ ≤^ f (

n )^ ≤^ cg ( n ) for all

n^ ≥^ n.^0

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

Asymptotic notation O -notation (upper bounds): We write^

f ( n ) =^ O ( g

( n )) if there exist constants

c^ > 0,^ n^0

0 such that 0^ ≤^ f (

n )^ ≤^ cg ( n ) for all

n^ ≥^ n.^0 We write^

f ( n ) =^ O ( g

( n )) if there exist constants

c^ > 0,^ n^0

0 such that 0^ ≤^ f (

n )^ ≤^ cg ( n ) for all

n^ ≥^ n.^0

EXAMPLE^ :

(^2) 2 n =^ O ( (^3) n )^ ( c^ = 1,

n = 2)^0 functions,not values

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

Asymptotic notation O -notation (upper bounds): We write^

f ( n ) =^ O ( g

( n )) if there exist constants

c^ > 0,^ n^0

0 such that 0^ ≤^ f (

n )^ ≤^ cg ( n ) for all

n^ ≥^ n.^0 We write^

f ( n ) =^ O ( g

( n )) if there exist constants

c^ > 0,^ n^0

0 such that 0^ ≤^ f (

n )^ ≤^ cg ( n ) for all

n^ ≥^ n.^0

EXAMPLE^ :

(^2) 2 n =^ O ( (^3) n )^ ( c^ = 1,

n = 2)^0 functions,not values

funny, “one-way”equality

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

Set definition of O-notation O ( g ( n )) = {^

f ( n ) : there exist constants^ c^ > 0,

n > 0 such^0 that 0 ≤^ f ( n )^ ≤^ cg

( n ) for all^ n^ ≥

n }^0 O ( g ( n )) = {

f ( n ) : there exist constants^ c^ > 0,

n > 0 such^0 that 0 ≤^ f ( n )^ ≤^ cg

( n ) for all^ n^ ≥

n }^0 EXAMPLE^ :

(^2) 2 n ∈^ O ( (^3) n )

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

Set definition of O-notation O ( g ( n )) = {^

f ( n ) : there exist constants^ c^ > 0,

n > 0 such^0 that 0 ≤^ f ( n )^ ≤^ cg

( n ) for all^ n^ ≥

n }^0 O ( g ( n )) = {

f ( n ) : there exist constants^ c^ > 0,

n > 0 such^0 that 0 ≤^ f ( n )^ ≤^ cg

( n ) for all^ n^ ≥

n }^0 EXAMPLE^ :

(^2) 2 n ∈^ O ( (^3) n ) ( Logicians:

(^2) λ n .2 n ∈

(^3) O (λ n. n ), but it’s

convenient to be sloppy, as long as weunderstand what’s

really^ going on.)

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

Macro substitution Convention:^ A set in a formula representsan anonymous function in the set.^ f ( n

(^3) ) = n +^ O (^2) ( n ) means^3 f ( n ) =^ n +

h ( n ) for some^ h

( n )^ ∈^ O ( n

EXAMPLE^ :

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

Macro substitution Convention:^ A set in a formula representsan anonymous function in the set.^2^ n

+^ O ( n ) =^

(^2) O ( n ) means for any^ f ( n

)^ ∈^ O ( n ): (^2) n + f ( n ) =^ h ( n ) for some^ h ( n )^ ∈

(^2) O ( n ).

EXAMPLE^ :

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

Ω -notation (lower bounds) O -notation is an

upper-bound

notation. It

makes no sense to say

f ( n ) is at least

(^2) O ( n ).

Ω( g ( n )) = {

f ( n ) : there exist constants^ c^ > 0,

n > 0 such^0 that 0 ≤^ cg ( n )^ ≤

f ( n ) for all^ n^ ≥

n }^0 Ω( g ( n )) = {

f ( n ) : there exist constants^ c^ > 0,

n > 0 such^0 that 0 ≤^ cg ( n )^ ≤

f ( n ) for all^ n^ ≥

n }^0

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

Ω -notation (lower bounds) O -notation is an

upper-bound

notation. It

makes no sense to say

f ( n ) is at least

(^2) O ( n ).

Ω( g ( n )) = {

f ( n ) : there exist constants^ c^ > 0,

n > 0 such^0 that 0 ≤^ cg ( n )^ ≤

f ( n ) for all^ n^ ≥

n }^0 Ω( g ( n )) = {

f ( n ) : there exist constants^ c^ > 0,

n > 0 such^0 that 0 ≤^ cg ( n )^ ≤

f ( n ) for all^ n^ ≥

n }^0

EXAMPLE^ :

( c^ = 1,^ n^0

)(lg n n^ Ω=

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

Θ -notation (tight bounds)^ Θ( g ( n )) = O(

g ( n ))^ ∩ Ω

( g ( n )) Θ( g ( n )) = O(

g ( n ))^ ∩ Ω

( g ( n )) )( (^221 2) nnn Θ=− 2 EXAMPLE^ :

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

ο -notation and

ω -notation

O -notation and

Ω-notation are like

≤^ and^ ≥.

o -notation and

ω-notation are like < and >.

ο( g ( n )) = {

f ( n ) : for any constant

c^ > 0, there is a constant

n > 0^0 such that 0

≤^ f ( n )^ <^ cg

( n ) for all^ n^ ≥

n }^0

ο( g ( n )) = {

f ( n ) : for any constant

c^ > 0, there is a constant

n > 0^0 such that 0

≤^ f ( n )^ <^ cg

( n ) for all^ n^ ≥

n }^0 EXAMPLE^ :

( n = 2/ c )^0 (^2 32) n =^ o ( n

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

Solving recurrences • The analysis of merge sort from

Lecture 1

required us to solve a recurrence. • Recurrences are like solving integrals,differential equations, etc.^ o^ Learn a few tricks. • Lecture 3 : Applications of recurrences todivide-and-conquer algorithms.

September 12, 2005^

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson

L2.

Substitution method The most general method: 1. Guess^ the form of the solution. 2. Verify^ by induction. 3. Solve^ for constants.