Algorithm Basics
Algorithm Basics
NOTES
What is an Algorithm? Algorithm Basics
The word Algorithm means ” A set of rules to be followed in calculations or other problem-solving
operations ” Or ” A procedure for solving a mathematical problem in a finite number of steps that
frequently involves recursive operations”.
Therefore Algorithm refers to a sequence of finite steps to solve a particular problem.
Algorithms can be simple and complex depending on what you want to achieve.
It can be understood by taking the example of cooking a new recipe. To cook a new recipe, one reads
the instructions and steps and executes them one by one, in the given sequence. The result thus
obtained is the new dish cooked perfectly. Every time you use your phone, computer, laptop, or
calculator you are using Algorithms. Similarly, algorithms help to do a task in programming to get the
expected output.
The Algorithm designed are language-independent, i.e. they are just plain instructions that can be
implemented in any language, and yet the output will be the same, as expected.
What are the Characteristics of an Algorithm?
As one would not follow any written instructions to cook the recipe, but only the standard one.
Similarly, not all written instructions for programming is an algorithm. In order for some instructions to
be an algorithm, it must have the following characteristics:
Clear and Unambiguous: The algorithm should be clear and unambiguous. Each of its steps
should be clear in all aspects and must lead to only one meaning.
Well-Defined Inputs: If an algorithm says to take inputs, it should be well-defined inputs.
Well-Defined Outputs: The algorithm must clearly define what output will be yielded and it
should be well-defined as well.
Finite-ness: The algorithm must be finite, i.e. it should terminate after a finite time.
Feasible: The algorithm must be simple, generic, and practical, such that it can be executed with
the available resources. It must not contain some future technology or anything.
Language Independent: The Algorithm designed must be language-independent, i.e. it must be
just plain instructions that can be implemented in any language, and yet the output will be the same,
as expected.
Properties of Algorithm:
It should terminate after a finite time.
It should produce at least one output.
It should take zero or more input.
It should be deterministic means giving the same output for the same input case.
Every step in the algorithm must be effective i.e. every step should do some work.
Advantages of Algorithms:
It is easy to understand.
An 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.
Understanding complex logic through algorithms can be very difficult.
Branching and Looping statements are difficult to show in Algorithms(imp).
// C++ program to add three numbers with the help of above designed algorithm
#include <iostream.h>
#include <conio.h>
int main()
{
// Variables to take the input of the 3 numbers
int num1, num2, num3;
return 0;
}