What is Algorithm? - CodeTextPro

 What is Algorithm? 

A finite set of instruction that specifies a sequence of operation is to be carried out in order to solve a specific problem or class of problems is called an Algorithm.

Algorithm Design

The important aspects of algorithm design include creating an efficient algorithm to solve a problem in an efficient way using minimum time and space.

To solve a problem, different approaches can be followed. Some of them can be efficient with respect to time consumption, whereas other approaches may be memory efficient. However, one has to keep in mind that both time consumption and memory usage cannot be optimized simultaneously. If we require an algorithm to run in lesser time, we have to invest in more memory and if we require an algorithm to run with lesser memory, we need to have more time.

Problem Development Steps

The following steps are involved in solving computational problems.
  • Problem definition
  • Development of a model
  • Specification of an Algorithm
  • Designing an Algorithm
  • Checking the correctness of an Algorithm
  • Analysis of an Algorithm
  • Implementation of an Algorithm
  • Program testing
  • Documentation
An algorithm must have the following properties:

  • Correctness: It should produce the output according to the requirement of the algorithm 
  • Finiteness: Algorithm must complete after a finite number of instructions have been executed. 
  • An Absence of Ambiguity: Each step must be defined, having only one interpretation. 
  • Definition of Sequence: Each step must have a unique defined preceding and succeeding step. The first step and the last step must be noted. 
  • Input/output: Number and classification of needed inputs and results must be stated. 
  • Feasibility: It must be feasible to execute each instruction. 
  • Flexibility: It should also be possible to make changes in the algorithm without putting so much effort on it.
  • Efficient - Efficiency is always measured in terms of time and space requires implementing the algorithm, so the algorithm uses a little running time and memory space as possible within the limits of acceptable development time. 
  • Independent: An algorithm should focus on what are inputs, outputs and how to derive output without knowing the language it is defined. Therefore, we can say that the algorithm is independent of language.


Pseudocode gives a high-level description of an algorithm without the ambiguity associated with plain text but also without the need to know the syntax of a particular programming language.

The running time can be estimated in a more general manner by using Pseudocode to represent the algorithm as a set of fundamental operations which can then be counted.

Difference between Algorithm and Pseudocode

An algorithm is a formal definition with some specific characteristics that describes a process, which could be executed by a Turing-complete computer machine to perform a specific task. Generally, the word "algorithm" can be used to describe any high level task in computer science.

On the other hand, pseudocode is an informal and (often rudimentary) human readable description of an algorithm leaving many granular details of it. Writing a pseudocode has no restriction of styles and its only objective is to describe the high level steps of algorithm in a much realistic manner in natural language.

For example, following is an algorithm for Insertion Sort.

Algorithm: Insertion-Sort

Input: A list L of integers of length n
Output: A sorted list L1 containing those integers present in L
Step 1: Keep a sorted list L1 which starts off empty
Step 2: Perform Step 3 for each element in the original list L
Step 3: Insert it into the correct position in the sorted list L1.
Step 4: Return the sorted list
Step 5: Stop

Here is a pseudocode which describes how the high level abstract process mentioned above in the algorithm Insertion-Sort could be described in a more realistic way.

for i <- 1 to length(A)
x <- A[i]
j <- i
while j > 0 and A[j-1] > x
A[j] <- A[j-1]
j <- j - 1
A[j] <- x

Algorithm vs Program:

A finite set of instructions that specifies a sequence of operations to be carried out to solve a specific problem of a class of problem is called an algorithm. 

On the other hand, the Program doesn't have to satisfy the finiteness condition. For example, we can think of an operating system that continues in a "wait" loop until more jobs are entered. Such a program doesn't terminate unless the system crashes.

Given a Problem to solve, the design Phase produces an algorithm, and the implementation phase then generates a program that expresses the designed algorithm. So, the concrete expression of an algorithm in a particular programming language is called a program.

Post a Comment