1. Algorithm
In computer programming terms, an algorithm is a set of well-defined instructions to solve a
particular problem. It takes a set of input and produces a desired output. For example,
An algorithm to add two numbers:
Take two number inputs
Add numbers using the + operator
Display the result
An algorithm must satisfy the following criteria:
1. Input: An algorithm should have zero or more but should be a finite number of inputs. We
can also say that it is essential for any algorithm before starting. Input should be given to it
initially before the Algorithm begins.
2. Output: An algorithm must give at least one required result from the given set of input
values. These output values are known as the solution to a problem.
3. Definiteness: Each step must be clear, unambiguous, and precisely defined.
4. Finiteness: Finiteness means Algorithm should be terminated after a finite number of steps.
Also, each step should be finished in a finite amount of time.
5. Effectiveness: Each step of the Algorithm must be feasible i.e., it should be practically
possible to perform the action. Every Algorithm is generally expected to be effective.
Characteristics of an algorithm
Input: An algorithm must have either 0 or more inputs.
Output: An algorithm should have 1 or more desired output.
Unambiguous: Every Algorithm should be unambiguous and clear. It means that it’s every
step, and input/output should be clear and must have only one meaning.
Feasibility: Algorithm should be feasible with the available resource.
Finiteness: Algorithm should be terminated after a finite number of steps.
Independent: Algorithm should have a step-by-step direction of each level, which is
independent of programming language.
2. Advantages of Algorithms
It is easy to understand.
Algorithm is a step-wise representation of a solution to a given problem.
In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier
for the programmer to convert it into an actual program.
Disadvantages of Algorithms
Writing an algorithm takes a long time so it is time-consuming.
Branching and Looping statements are difficult to show in Algorithms.
How to Design an Algorithm?
In order to write an algorithm, following things are needed as a pre-requisite:
The problem that is to be solved by this algorithm.
The constraints of the problem that must be considered while solving the problem.
The input to be taken to solve the problem.
The output to be expected when the problem is solved.
The solution to this problem, in the given constraints.
Then the algorithm is written with the help of above parameters such that it solves the
problem
Algorithm Analysis
Algorithm analysis deals with the execution or running time of various operations involved. The
running time of an operation can be defined as the number of computer instructions executed per
operation.
Efficiency of an algorithm can be analyzed at two different stages, before implementation and after
implementation. They are the following
Apriori analysis of algorithms: it means we do analysis (space and time) of an algorithm prior
to running it on specific system - that is, we determine time and space complexity of algorithm by
just seeing the algorithm rather than running it on particular system (with different processor and
compiler).
Apostiari analysis of algorithms: it means we do analysis of algorithm only after running it on
system. It directly depends on system and changes from system to system.