ADA Module 1 Part 1
ADA Module 1 Part 1
ADA Module 1 Part 1
4. There may exist several algorithms for solving the same problem.
2) Decide on:
Computational means,
Exact vs. Approximate solving,
Algorithm design technique.
Computational means
Once you completely understand a problem, you need to find out
the capabilities of the computational device that you are
using for running the algorithm.
Exact vs. Approximate solving
The next important decision is to choose between solving the
problem exactly or solving it approximately.
Why would one opt for an approximation algorithm?
First, there are important problems that simply cannot be solved
exactly for most of their instances; examples include extracting
square roots, solving nonlinear equations, and evaluating definite
integrals.
Second, available algorithms for solving a problem exactly can be
unacceptably slow because of the problem’s intrinsic complexity.
Algorithm design technique
An algorithm design technique (or “strategy” or “paradigm”) is a
general approach to solving problems algorithmically that is applicable
to a variety of problems from different areas of computing.
Designing an Algorithm and Data Structures
After choosing algorithm design technique, one should pay close
attention to choosing data structures appropriate for the operations
performed by the algorithm.
Example: selected data structure array for solving the problem of
finding consecutive prime numbers.
Algorithms + Data Structures = Programs
Next task is to specify the algorithm either using natural language or
pseudo code convention.
4) Proving an Algorithm’s Correctness
Once an algorithm has been specified, you have to prove its
correctness.
That is, you have to prove that the algorithm yields a required result
for every legitimate input in a finite amount of time.
For example: the correctness of Euclid’s algorithm for gcd(m,n)
the simple observation that the second integer gets smaller on every
iteration of the algorithm, and the fact that the algorithm stops when
the second integer becomes 0.
If incorrect, think about redesigning the algorithm or
choose different data structures and redesign.
5) Analysing an Algorithm
After correctness, it’s time to analyse the algorithm for its efficiency.
Time efficiency, indicating how fast the algorithm runs,
Space efficiency, indicating how much memory it uses.
Also check for other two desirable characteristics of an algorithm is
simplicity and generality.
If you are not satisfied with the algorithm’s efficiency, simplicity, or
generality, you must return to the drawing board and redesign the
algorithm.
6) Coding an Algorithm
Convert algorithms into computer programs.
But unless the correctness of a computer program is proven with full
mathematical rigor, the program cannot be considered correct.
Testing of computer programs is an art rather than a science.
“As a rule, a good algorithm is a result of repeated effort and
rework”.
The Analysis Framework
General framework for analyzing the efficiency of algorithms
Note: The count C(n) does not contain any information about
operations that are not basic, and, in fact, the count itself is often
computed only approximately.
Order of Growth:
We expect the algorithms to work faster for all values of n. Some
algorithms execute faster for small values of n. But, as the value
of n increases, they tend to be very slow. So, the behaviour of
some algorithm changes with increase in value of n. This change
in behaviour of the algorithm and its efficiency can be analysed
by considering the highest order of n. The order of growth is
normally determined for larger values of n.