Professional Documents
Culture Documents
CSCI 3110
Previous Evaluations of
Programs
Correctness does the algorithm do what it
is supposed to do?
Generality does it solve only a specific
case or will it work for the general case too?
Robustness will the algorithm recover
following an error
Portability
Documentation & Style
Efficiency Does it accomplish its goals with
a minimal usage of computer resources (time
and space)?
Time Complexity
Best time
The minimum amount of time required by the
algorithm for any input of size n.
Seldom of interest.
Average time
The average amount of time required by the
algorithm over all inputs of size n
Algorithm Efficiency
The efficiency of an algorithm is
determined in terms of the order of
growth of the function.
Only compare the rate of growth (order of
magnitude) of the functions and compare
the orders. -- how fast does the algorithm
grow as the size of input, N, grows?
Normally, the growth function will approach
some simpler function asymptotically.
For growth functions having different orders
of magnitude, exact frequency counts and
the constants become insignificant.
Examples
F(n)
F(n)
F(n)
F(n)
=
=
=
=
Example
Show by definition that f(n) = 3n + 2 is
O(n).
By definition, we must show there exist C
and n0 such that 3n+2 < C n for all n > n 0
where n0 is a non-negative integer.
Let C = 4. Why did I pick 4?
If C = 4, 3n+2 < 4n when? Subtract 3n from
both sides of the inequality: 3n + 2 3n < 4n
3n or 2 < n. Thus n0 is 2.
Is this the only C and n0 that will work?
Intuitive interpretation of
growth functions
A GFR of O(1) implies a problem
whose time requirement is constant &
thus independent of the problems size n.
Intuitive interpretation
continued
A GFR of O(1) implies a problem
For which the time requirement is directly
proportional to the size of the problem.
In which if you square the problem size,
you also square its time requirement
That often has a single loop from 1 to n
Intuitive interpretation
continued
A GFR of O(n2) is a problem
For which the time requirement increases
rapidly with the size of the problem
That often has two nested loops