Definition
An algorithm is a sequence(step-by-step) of
unambiguous instructions to solve a problem for obtaining a
required output for any legitimate input in a finite amount of
time.
Algorithmics is more than a branch of computer science, it is
the core of computer science and in all fairness can be said
to be relevant to most of science, business, and technology.
Reason for studying algorithms is their usefulness in
developing analytical skills. After all, algorithms can be
seen as special kinds of solutions to problems. It is like the
mixture of mathematics and programming.
Simple Example
Algorithm to find the sum of two numbers.
- Start
- Read num1, num2
- sum = num1+num2
- Display sum
- Stop
Important points about Algorithms
-
The non-ambiguity requirement for each step of an algorithm
cannot be compromised.
-
The range of inputs for which an algorithm works has to be
specified carefully.
-
There maybe more than one algorithm for solving the same
problem.
- The same algorithm can be implemented in several ways.
-
Algorithms for the same problem can be based on different
ideas and can solve the problem with dramatically different
speeds.
Characteristics
- Inputs: 0 or more no. of inputs
- Outputs: 1 or more no. of outputs
-
Unambiguity: Clear & Simple instructions.
-
Finiteness: Limited no. of instructions/steps
to solve the problem
-
Effectiveness: Each instruction has an impact
on overall process.
Notion of an Algorithm
- First we look into the problem.
-
We write an algorithm for the problem and feed it into the
computer.
-
We then provide inputs to check the correctness of the
algorithm.
-
Finally we get the output/s based on how the algorithm was
written.
Design and Analysis of Algorithms
-
The first thing you need to do before designing an
algorithm is to understand completely the problem given.
Read the problem’s description carefully and do a few
small examples by hand, think about special cases.
-
Once you completely understand a problem, you need to
ascertain the capabilities of the computational device the
algorithm is intended for. The next principal decision is
to choose between solving the problem exactly or solving
it approximately.
-
An algorithm design technique is a general approach to
solving problems algorithmically that is applicable to a
variety of problems from different areas of computing.
Design a simple algorithm that could approximately solve
the problem.
-
Prove the correctness by providing inputs of your own and
try to get the required output. That is, you have to prove
that the algorithm yields a required result for every
legitimate input in a finite amount of time.
-
We usually want our algorithms to possess several
qualities and be more efficient. In fact, there are two
kinds of algorithm efficiency:
time efficiency (indicating how fast the
algorithm runs) and
space efficiency (indicating how much
extra memory it uses).
-
Finally, code the algorithm with your preferred
programming language.