Ch2 ppt Fundamentals of Analysis of Algorithm Efficiency Flashcards
The time required by the algorithm
Time efficiency/ complexity
The time required by the algorithm
space efficiency/complexity
Analyzing the running time efficiency of algorithms
What to analyze?
The size of the input is the main consideration for analyzing the
running time,
Count the number of times each of the algorithm’s operations (of
loops/recursions) is executed
The running time of algorithms can be different. Best case of the
running time is of little interest, average case is difficult to
calculate (not apparent what constitutes an “average” input for a
problem, worst case representing the running time, that is, the
longest running time for any input size, n.
The eight most important functions, f(n), used in the
analysis of algorithms
– The Constant Function (1)
– The Logarithm2
Function (log2n)
– The Linear Function (n)
– The N-Log2
-N Function (nlog2n)
– The Quadratic Function (n2)
– The Cubic Function and Other Polynomials (n3)
– The Exponential Functions (2n)
– The Factorial Functions (n!)
the constant function
f(n) = c for some fixed constant c where n is the input
size.
The logarithm function
f(n) = log2n = x if and only if 2
x = n where 2 is the
base and n represents the input size.
– By definition, log{2}1 = 0
the linear function
f(n) = log2n = x if and only if 2
x = n where 2 is the
base and n represents the input size.
– By definition, log21 = 0
the N-log{2}-N function
f(n) = n log2 n where n is the input size.
The quadratic function
f(n) = n^2 where n is the input size.
the cubic function and other polynomials
f(n) = n^3 where n is the input size.
the exponential function
f(n) = 2^n, 3^n , …, or n^n where n represents the
input size.
factorial function
f(n) = n! where n represents the input size.
Notations used to describe the
running time of algorithms
asymptotic notation
O-notation (upper bound)
Let f(n) and g(n) be functions that f(n) is bounded above
by some constant multiple of g(n)
Omega notation (lower bound)
Let f(n) and g(n) be functions that f(n) is bounded
below by some constant multiple of g(n)