What is an Algorithm?
An algorithm is a sequence of finite instructions, often used for calculation and data processing. It is formally a type of effective method in which a list of well-defined instructions for completing a task will, when given an initial state, proceed through a well-defined series of successive states, eventually terminating in an end state.
A step-by-step method of solving a problem or making decisions, as in making a diagnosis. An established mechanical procedure for solving certain mathematical problems.
Properties of the algorithm
- Finiteness. An algorithm must always terminate after a finite number of steps and each step must finish in a finite amount of time.
- Definiteness. (no Ambiguity) Each step of an algorithm must be precisely defined; the actions to be carried out must be rigorously and unambiguously specified for each case.
- Input. An algorithm has zero or more but must be a finite number of inputs, i.e, quantities that are given to it initially before the algorithm begins.
- Output. An algorithm must have at least one desirable outcome.
- Effectiveness. An algorithm should be effective. Effective means that each step should be referred to as a principle and executed in a finite time.
Write an algorithm to find the largest among three different numbers entered by user.
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a>b
If a>c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b>c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop