Docsity

Data Structures & Algorithms: CSCE 350 Announcement - Efficiency & Growth Order - Prof. C., Study notes of Computer Science

Toggle sidebar
bg1
1
CSCE 350:
Data Structures and Algorithms
Chin-Tser Huang
University of South Carolina
01/26/2009 2
Announcement
Reading assignment: Chapter 2.3
Homework 1 due on Friday, January 30
in class
01/26/2009 3
Amortized Efficiency
Apply to a sequence of operations performed
on the same data structure instead of to a
single run
In some cases a single operation may be
expensive, but the total time for an entire
sequence of n operations is significantly better
than n * (worst case efficiency of that single
operation)
Similar to businesses amortizing an expensive item
over its productive lifetime
01/26/2009 4
Summary of Analysis Framework
Both time and space efficiencies are measured as
functions of
input size
Time efficiency is measured by
counting number of
times the algorithm’s basic operation is executed
;
space efficiency is measured by
counting number of
extra memory units consumed by algorithm
Efficiencies of some algorithms may differ
significantly for different inputs of same size
Primary interest lies in the
order of growth
of the
algorithm’s running time/extra memory units
consumed as its input size goes to infinity
01/26/2009 5
Asymptotic order of growth
A way of comparing functions that ignores
constant factors and small input sizes
O(
g
(
n
)): class of functions
f
(
n
) that grow no faster than
g
(
n
)
Θ(
g
(
n
)): class of functions
f
(
n
) that grow at same rate
as
g
(
n
)
Ω(
g
(
n
)): class of functions
f
(
n
) that grow at least as fast
as
g
(
n
)
01/26/2009 6
Big-oh
pf2

Partial preview of the text

Download Data Structures & Algorithms: CSCE 350 Announcement - Efficiency & Growth Order - Prof. C. and more Study notes Computer Science in PDF only on Docsity!

CSCE 350:

Data Structures and Algorithms

Chin-Tser Huang

[email protected]

University of South Carolina

01/26/2009 2

Announcement

„ Reading assignment: Chapter 2.

„ Homework 1 due on Friday, January 30

in class

01/26/2009 3

Amortized Efficiency

„ Apply to a sequence of operations performed

on the same data structure instead of to a

single run

„ In some cases a single operation may be

expensive, but the total time for an entire

sequence of n operations is significantly better

than n * (worst case efficiency of that single

operation)

„ Similar to businesses amortizing an expensive item

over its productive lifetime

01/26/2009 4

Summary of Analysis Framework

„ Both time and space efficiencies are measured as

functions ofinput size

„ Time efficiency is measured bycounting number of

times the algorithm’s basic operation is executed;

space efficiency is measured bycounting number of

extra memory units consumed by algorithm

„ Efficiencies of some algorithms may differ

significantly for different inputs of same size

„ Primary interest lies in theorder of growth of the

algorithm’s running time/extra memory units

consumed as its input size goes to infinity

01/26/2009 5

Asymptotic order of growth

A way of comparing functions that ignores

constant factors and small input sizes

„ O(g(n)): class of functionsf(n) that grow no faster than

g(n)

„ Θ(g(n)): class of functionsf(n) that grow at same rate

asg(n)

„ Ω(g(n)): class of functionsf(n) that grow at least as fast

asg(n)

01/26/2009 6

Big-oh

01/26/2009 7

Big-omega

01/26/2009 8

Big-theta

01/26/2009 9

Establishing order of growth using

the definition

Definition:f(n) is in O(g(n)) if order of growth

off(n) ≤ order of growth ofg(n) (within

constant multiple),

i.e., there exist positive constantc and non-

negative integern

0

such that

f(n) ≤ c g(n) for everyn ≥ n

0

Examples:

„ 10 n is O(n

2

)

„ 5 n+20 is O(n)

01/26/2009 10

Some properties of asymptotic order

of growth

„ f(n) ∈ O(f(n))

„ f(n) ∈ O(g(n)) iffg(n) ∈Ω(f(n))

„ Iff (n) ∈ O(g (n)) andg(n) ∈ O(h(n)) , then

f(n) ∈ O(h(n))

Note similarity witha ≤ b

„ Iff

1

(n) ∈ O(g

1

(n)) andf

2

(n) ∈ O(g

2

(n)) , then

f

1

(n) +f

2

(n) ∈ O(max{g

1

(n),g

2

(n)})

01/26/2009 11

Establishing order of growth using

limits

lim n→∞

T(n)/g(n) =

0 order of growth of T ( n ) ___ order of growth of g ( n )

c >0 order of growth of T ( n ) ___ order of growth of g ( n )

∞ order of growth of T ( n ) ___ order of growth of g ( n )

Examples: Examples:

  • 10 n vs. 2 n

2

  • n ( n +1)/2 vs. n

2

  • log

b

n vs. log

c

n (b>c> 1 )

01/26/2009 12

L’Hôpital’s rule and Stirling’s formula

L’Hôpital’s rule : Iflim

n→∞

f(n) =lim

n→∞

g(n) = ∞ and

the derivativesf´,g´ exist, then

Stirling’s formula :n! ≈ (2π n)

1/

(n/e)

n

f

f (

n

n )

g

g (

n

n )

lim lim

n

n →∞

→∞

f

f ´

n

n )

g

g ´

n

n )

limlim

n

n →∞

→∞

Example: log

2

n vs. n

1/

Example: n! vs. 2

n