Algorithms Pseudo Code

Advertisements
Advertisements

 13 total views

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.

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];
          }
}

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.

Advertisements

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

Bestseller

Introduction to Algorithms, 3rd Edition (The MIT Press) 3rd Edition

Best book for students with little programming experience. The algorithms are designed and explained in easy to understand manner. The book includes many exercises and problems. The text is intended primarily for students studying algorithms or data structures. As it discusses engineering issues in algorithm design, as well as mathematical aspects, it is equally well suited for self-study by technical professionals.

Advertisements
Advertisements
Advertisements