How to measure
the "goodness" of
computer programs
- Question:
- How can do we
measure the
"goodness" of
a program/algorithm ?
|
- Possible
performance mesaures:
- Running time
(the shorter, the
better)
- Memory utilization
(the less, the
better)
- Amount of code ??
- Etc
|
-
Most commonly used
performance (= "goodness") measure:
|
How to
measure the
running time of
a program/algorithm ?
What is a
primitive operation ?
-
Recall
that
algorithms
make repeated
steps
towards the
solution...
- The
primitive operation
is
a
step in
the algorithm
- Example:
- Suppose the
main body of an
algorithm looks like this:
for ( int i = 0; i < N; i++ }
{
S1; --+
S2; |
... | 1 step = execute S1, S2, ..., SN
SN; --+
}
|
- Then the
primitive operation
of this algorithm consists of
the statements
S1; S2; ...; SN;
|
|
Principles
of Algorithm Analysis
- Algorithm Analysis
consists of:
- Determine frequency (= count)
of primitive operations
- Characterize the
frequency as
a function of
the input size
|
- The Algorithm Analysis must:
- Take into account all possible
inputs
("good" one and "bad" ones)
- Be independent of
hardware/software
environment
- Be independent from
the programming language
- Give a
good estimate that is
proportional to
the actual
running time of
the algorithm
|
|
"Good" inputs, "Bad" inputs and "Average" case
Worst-case vs. Average-case Analysis
- Worst case
analysis:
- Provides an
upper bound on the
running time of
an algorithm
- The analysis is
easier to
do (compared to
an average case
analysis)
|
- Average case
analysis:
- Take the average (running time)
over all possible
inputs of the
same size
- The analysis
depends on
input distribution
- The analysis is
harder to
do because it uses
probability techniques
|
|
Techniques used in
Algorithm Analysis
❮
❯