Algorithm: Characteristics of An Algorithm

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Algorithm

The word Algorithm means “a process or set of rules to be followed in calculations or other
problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-
by-step define how a work is to be executed upon in order to get the expected results.

Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a


certain order to get the desired output. Algorithms are generally created independent of
underlying languages, i.e. an algorithm can be implemented in more than one programming
language.

Characteristics of an Algorithm
 Clear and Unambiguous: 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.
 Finiteness: The algorithm must be finite, i.e. it should not end up in an infinite loops or
similar.
 Feasible: The algorithm must be simple, generic and practical, such that it can be
executed upon will 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 same, as expected.

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

An algorithm in programming will have several steps as follows –


1. Problem definition – What is to be done?
2. Data collection – What do we have to solve the problem? Or inputs.
3. Data processing – Understanding what we have or transforming them into a usable
form.
4. Logical approach – Employing the collected & created data against logic to solve.
5. Solution – Present the solution

Addition of two numbers


Input: a, b
Output: c

1. Start.
2. Input two numbers a and b.
3. c = a + b.
4. Print c.
5. Stop.

Average of three numbers

Input: a, b, c
Output: avg

1. Start
2. Enter a, b, c.
3. avg = (a+b+c)/3
4. Print avg
5. Stop

Swapping of two numbers

Input: a, b, c
Output: a, b

1. Start
2. Enter a, b.
3. C=a
4. A=b
5. B=c
6. Print a, b
7. Stop

Swapping of two numbers without third variable

Input: a, b
Output: a, b

1. Start
2. Enter a, b.
3. A = a+b
4. B = a-b
5. A = a-b
6. Print a, b
7. Stop

You might also like