Ch3 Algorithm Analysis
Ch3 Algorithm Analysis
Running Time
80
with the input size.
60
Average case time is often
difficult to determine. 40
running time. 0
1000 2000 3000 4000
Easier to analyze Input Size
Crucial to applications such as
games, finance and robotics
© 2013 Goodrich, Tamassia, Goldwasser Analysis of Algorithms 2
Experimental Studies
Write a program 9000
Time (ms)
5000
time needed:
4000
3000
2000
1000
0
Plot the results 0 50 100
Input Size
An potentially unbounded
bank of memory cells, 2
1
each of which can hold an 0
arbitrary number or
character
Memory cells are numbered and accessing
any cell in memory takes unit time.
© 2013 Goodrich, Tamassia, Goldwasser Analysis of Algorithms 8
Seven Important Functions
Seven functions that
often appear in algorithm 1E+30
1E+28
analysis: 1E+26
Cubic
Constant 1 1E+24 Quadratic
Logarithmic log n 1E+22
Linear
1E+20
Linear n 1E+18
N-Log-N n log n 1E+16
T (n )
1E+14
Quadratic n2 1E+12
Cubic n3 1E+10
Exponential 2n 1E+8
1E+6
1E+4
In a log-log chart, the 1E+2
slope of the line 1E+0
corresponds to the 1E+0 1E+2 1E+4 1E+6 1E+8 1E+10
n
growth rate
© 2013 Goodrich, Tamassia, Goldwasser Analysis of Algorithms 9
Slide by Matt Stallmann
Functions Graphed included with permission.
g(n) = n2
g(n) = lg n
g(n) = n
g(n) = n3
1
1 10 100 1,000
n
big-Theta
f(n) is (g(n)) if there are constants c’ > 0 and c’’
equal to g(n)