0% found this document useful (0 votes)
43 views4 pages

Pseudo Code

Pseudocode is a step-by-step description of an algorithm using simple English, aimed at human understanding rather than machine reading. It serves as an intermediate state between an idea and its implementation in a programming language, aiding both programmers in planning solutions and readers in comprehending the approach. Key guidelines for writing pseudocode include organizing tasks, using standard programming structures, and ensuring clarity and simplicity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views4 pages

Pseudo Code

Pseudocode is a step-by-step description of an algorithm using simple English, aimed at human understanding rather than machine reading. It serves as an intermediate state between an idea and its implementation in a programming language, aiding both programmers in planning solutions and readers in comprehending the approach. Key guidelines for writing pseudocode include organizing tasks, using standard programming structures, and ensuring clarity and simplicity.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

A Pseudocode is defined as a step-by-step description of an algorithm.

Pseudocode does not use any


programming language in its representation instead it uses the simple English language text as it is
intended for human understanding rather than machine reading.
Pseudocode is the intermediate state between an idea and its implementation(code) in a high-level
language.

What is the need for Pseudocode

Pseudocode is an important part of designing an algorithm, it helps the programmer in planning the
solution to the problem as well as the reader in understanding the approach to the problem.
Pseudocode is an intermediate state between algorithm and program that plays supports the
transition of the algorithm into the program.

Pseudocode is an intermediate state between algorithm and program

How to write Pseudocode?

Before writing the pseudocode of any algorithm the following points must be kept in mind.

 Organize the sequence of tasks and write the pseudocode accordingly.

 At first, establishes the main goal or the aim. Example:

This program will print first N numbers of Fibonacci series.

 Use standard programming structures such as if-else, for, while, and cases the way we use
them in programming. Indent the statements if-else, for, while loops as they are indented in
a program, it helps to comprehend the decision control and execution mechanism. It also
improves readability to a great extent. Example:

IF “1”
print response
“I AM CASE 1”

IF “2”
print response
“I AM CASE 2”

 Use appropriate naming conventions. The human tendency follows the approach of
following what we see. If a programmer goes through a pseudo code, his approach will be
the same as per that, so the naming must be simple and distinct.

 Reserved commands or keywords must be represented in capital letters. Example: if you are
writing IF…ELSE statements then make sure IF and ELSE be in capital letters.
 Check whether all the sections of a pseudo code are complete, finite, and clear to
understand and comprehend. Also, explain everything that is going to happen in the actual
code.

 Don’t write the pseudocode in a programming language. It is necessary that the pseudocode
is simple and easy to understand even for a layman or client, minimizing the use of technical
terms.

Good vs Bad ways of writing Pseudocode:

Pseudocode Examples:

1. Binary search Pseudocode:

Binary search is a searching algorithm that works only for sorted search space. It repeatedly divides
the search space into half by using the fact that the search space is sorted and checking if the desired
search result will be found in the left or right half.

Example: Given a sorted array Arr[] and a value X, The task is to find the index at which X is present
in Arr[].

Below is the pseudocode for Binary search.

BinarySearch(ARR, X, LOW, HIGH)


repeat till LOW = HIGH
MID = (LOW + HIGH)/2
if (X == ARR[mid])
return MID

else if (x > ARR[MID])


LOW = MID + 1
else
HIGH = MID – 1

2. Quick sort Pseudocode:

QuickSort is a Divide and Conquer algorithm. It picks an element as a pivot and partitions the given
array around the picked pivot.

Say last element of array is picked as pivot then all elements smaller than pivot element are shifted
on the left side of pivot and elements greater than pivot are shifted towards the right of pivot by
swapping, the same algorithm is repeatedly followed for the left and right side of pivot until the
whole array is sorted.

Below is the pseudocode for Quick sort

QUICKSORT(Arr[], LOW, HIGH) {


if (LOW < HIGH) {
PIVOT = PARTITION(Arr, LOW, HIGH);
QUICKSORT(ARR, LOW, PIVOT – 1);
QUICKSORT(ARR, PIVOT + 1, HIGH);
}
}

Here, LOW is the starting index and HIGH is the ending index.

Difference between Algorithm and Pseudocode

Algorithm Pseudocode

An Algorithm is used to provide a solution to a A Pseudocode is a step-by-step description of


particular problem in form of a well-defined an algorithm in code-like structure using
step-based form. plain English text.

Pseudocode also uses reserved keywords like


An algorithm only uses simple English words
if-else, for, while, etc.

These are fake codes as the word pseudo


These are a sequence of steps of a solution to a
means fake, using code like structure and
problem
plain English text

There are certain rules for writing


There are no rules to writing algorithms
pseudocode

Pseudocode cannot be considered an


Algorithms can be considered pseudocode
algorithm
Algorithm Pseudocode

It is difficult to understand and interpret It is easy to understand and interpret

Difference between Flowchart and Pseudocode

Flowchart Pseudocode

A Pseudocode is a step-by-step description


A Flowchart is pictorial representation of flow of
of an algorithm in code like structure using
an algorithm.
plain English text.

A Flowchart uses standard symbols for input,


Pseudocode uses reserved keywords like if-
output decisions and start stop statements. Only
else, for, while, etc.
uses different shapes like box, circle and arrow.

This is a way of visually representing data, these These are fake codes as the word pseudo
are nothing but the graphical representation of means fake, using code like structure but
the algorithm for a better understanding of the plain English text instead of programming
code language

Pseudocode is better suited for the purpose


Flowcharts are good for documentation
of understanding

You might also like