Algorithms Pseudo Code

In this article, you will learn how to represent an algorithm using a pseudo code and elements of pseudo codes. Learning a programming language is not necessary to understand pseudo code, but knowing a programming language like C, Pascal, etc. help you understand the pseudo codes better.

Advertisements

Algorithms Components

The algorithm has two part – heading and the body. See the table below for more information.

 NotationDescription
HeadingAlgorithm <Name>(<parameter-list>)has the name of the procedure and parameters
Body{ }two braces indicates block of statements
Head and Body of an Algorithm

Example:

Algorithm Find_Max( A[n])
{

// A[n] is the list of unsorted numbers from which
// we need to  find Max value.
        max := 0;
        for i := i to n do
           if max  >= A[i] then
          {  
             max := A[i];
          }
}
Advertisements

The above is sample algorithm to find max value from a list of numbers. The algorithm is written in pseudo code and contains lot of elements with their own notations.

Notations

See the table below to understand each notation because you need them for writing algorithms.

Element NameNotationDescription
Comments//start with // till the end of line.
Block{ }indicate a block of statements.
Identifierdummy-variablestarts with a letter, variable data type is not defined.
Assignments<var> := <value>assignments are done using := operator
Logical Operatorsand , or , notcan use logical operators in expressions.
Relational Operators>, <, <=, >=, !=relational operators are allowed
Single Dimensional ArrayA[j]jth element of single dimensional array
Multi-Dimensional ArrayA[i, j]represents a multidimensional array, (i, j) th element.
While loopwhile <condition > do {
}
a while loop structure
For loopfor var:= value 1 to value 2 step do {
}
a for loop structure
Conditional statement  if – thenif <condition> then <statement>if  block of statements
Conditional statement if – then – elseif <condition> then <statement> else <statement>if – else block of statements
Inputreadcommand to read input values
Outputwritecommand to write output values
Nodenode = record {
data type 1 data1;
data type 2 data2;

node *link;

}
A compound data type make of other data types
Codes used in Algorithms
Advertisements

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.