What is PseudoCode: A Complete Tutorial
Last Updated :
26 Jul, 2025
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 PseudoCode: A Complete TutorialWhat 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 programBefore 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:
Good Vs Bad way of writing PseudocodePseudocode 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.
Algorithm | Pseudocode |
---|
An Algorithm is used to provide a solution to a particular problem in form of a well-defined step-based form. | A Pseudocode is a step-by-step description of an algorithm in code-like structure using plain English text. |
An algorithm only uses simple English words | Pseudocode also uses reserved keywords like if-else, for, while, etc. |
These are a sequence of steps of a solution to a problem | These are fake codes as the word pseudo means fake, using code like structure and plain English text |
There are no rules to writing algorithms | There are certain rules for writing pseudocode |
Algorithms can be considered pseudocode | Pseudocode cannot be considered an algorithm |
It is difficult to understand and interpret | It is easy to understand and interpret |
Difference between Flowchart and Pseudocode
Flowchart | Pseudocode |
---|
A Flowchart is pictorial representation of flow of an algorithm. | A Pseudocode is a step-by-step description of an algorithm in code like structure using plain English text. |
A Flowchart uses standard symbols for input, output decisions and start stop statements. Only uses different shapes like box, circle and arrow. | Pseudocode uses reserved keywords like if-else, for, while, etc. |
This is a way of visually representing data, these are nothing but the graphical representation of the algorithm for a better understanding of the code | These are fake codes as the word pseudo means fake, using code like structure but plain English text instead of programming language |
Flowcharts are good for documentation | Pseudocode is better suited for the purpose of understanding |
1. Infosys Pseudocode Questions:
What will be the output of the following pseudocode?
Question 1) for i=0 to 4 step 1 do
If i==i++ + --i then do
display i
end-if
end-for
Answer: 0
Question 2) Set Character c = '7'
switch(c)
case '1': display "One"
case '7': display "Seven"
case '2': display "Two"
default: display "Hello"
break
end-switch
Answer: SevenTwoHello
Question 3) Integer a, p
Set a = 5
a = a + 1
a = a * 2
a = a / 2
p = a / 5 + 6
print p
Answer: 7
Question 4) Integer a, b, c
Set b = 40, a = 20, c = 20
a = a + c
c = c + a
a = a + c
c = c + a
Print a + b + c
Answer: 300
Question 5) Integer a, b, c
Set a = 4, b = 3, c = 1
if (a >> (c - 1) && b << (c + 1))
a = a + c
Else
b = a <<< C
End if
Print a - b + c
Answer: 3
2. Accenture Pseudocode Questions:
What will be the output of the following pseudocode?
Questions 1) What will be the output of the following pseudocode for a = 5, b = 1?
Integer funn(Integer a, Integer b)
if(b + a || a - b) && (b > a) && 1)
a = a+b+b-2
return 3-a
Else
return a-b+1
End if
return a + b
End function fun()
Answer: 5
Questions 2) What will be the output of the following pseudocode for a = 5, b = 1?
Integer funn(Integer a, Integer b)
if((b mod a && a mod b) || (a ^ b > a))
a=a ^ b
Else
return a-b
End if
return a + b
End function funn()
Answer: 5
Questions 3) What will be the output of the following pseudocode?
Integer a, b, c
Set a = 4, b = 4, c = 4
if (a & (b ^ b) & c)
a = a >> 1
End if
Print a + b + c
Answer: 12
Questions 4) What will be the output of the following pseudocode for a = 10, b = 11?
Integer funn(Integer a, Integer b)
if(0)
return a - b - funn(-7, -1)
End if
a = a + a + a + a
return a
End function funn()
Answer: 40
Questions 5) What will be the output of the following pseudocode for a = 5, b = 1?
Integer funn(Integer a, Integer b)
if(b + a || a - b) && (b > a) && 1)
a = a + b + b - 2
return 3 - a
Else
return a - b + 1
End if
return a + b
End function fun()
Answer: 5
3. Capgemini Pseudocode Questions
What will be the output of the following pseudocode?
Question 1) What will be the output of the following pseudocode for a=8, b=1?
Integer funn(Integer a, Integer b)
If(a > b && a > 0)
Return a + b + funn (b-1, a-1)
End if
Return a + b
Answer: 16
Question 2) What will be the output of the following pseudocode for p=7, q=2?
Integer funn(Integer p, Integer q)
if(p + q < 10)
Return 1 + funn(p + 1, q + 1)
Else
Return 2
End if
Answer: 3
Question 3) What will be the output of the following pseudocode for a=2, b=7, c=7?
Integer funn(Integer a, Integer b, Integer c)
if ((b + a) < (a - b))
a = a + c
b = (10 + 10) + c
End if
Return a + b + c
Answer: 16
Question 4) What will be the output of the following pseudocode?
String str1 = "err", str2 = "krr"
Print (count consonant(upper(reverse(str2) + reverse(str1))))
Answer: 5
Question 5) What will be the output of the following pseudo code?
Integer a, b, c
Set a = 2, b = 11, c = 5
if ((4 + 5) < (6 + b))
b = c & a
End if
Print a + b + c
Answer: 7
Conclusion:
In the above discussion, we understood the importance of pseudocode in understanding an algorithm. Pseudocode is a lot simpler to construct and debug as compared to an algorithm.
Similar Reads
Basics & Prerequisites
Data Structures
Array Data StructureIn this article, we introduce array, implementation in different popular languages, its basic operations and commonly seen problems / interview questions. An array stores items (in case of C/C++ and Java Primitive Arrays) or their references (in case of Python, JS, Java Non-Primitive) at contiguous
3 min read
String in Data StructureA string is a sequence of characters. The following facts make string an interesting data structure.Small set of elements. Unlike normal array, strings typically have smaller set of items. For example, lowercase English alphabet has only 26 characters. ASCII has only 256 characters.Strings are immut
2 min read
Hashing in Data StructureHashing is a technique used in data structures that efficiently stores and retrieves data in a way that allows for quick access. Hashing involves mapping data to a specific index in a hash table (an array of items) using a hash function. It enables fast retrieval of information based on its key. The
2 min read
Linked List Data StructureA linked list is a fundamental data structure in computer science. It mainly allows efficient insertion and deletion operations compared to arrays. Like arrays, it is also used to implement other data structures like stack, queue and deque. Hereâs the comparison of Linked List vs Arrays Linked List:
2 min read
Stack Data StructureA Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). LIFO implies that the element that is inserted last, comes out first and FILO implies that the element that is inserted first
2 min read
Queue Data StructureA Queue Data Structure is a fundamental concept in computer science used for storing and managing data in a specific order. It follows the principle of "First in, First out" (FIFO), where the first element added to the queue is the first one to be removed. It is used as a buffer in computer systems
2 min read
Tree Data StructureTree Data Structure is a non-linear data structure in which a collection of elements known as nodes are connected to each other via edges such that there exists exactly one path between any two nodes. Types of TreeBinary Tree : Every node has at most two childrenTernary Tree : Every node has at most
4 min read
Graph Data StructureGraph Data Structure is a collection of nodes connected by edges. It's used to represent relationships between different entities. If you are looking for topic-wise list of problems on different topics like DFS, BFS, Topological Sort, Shortest Path, etc., please refer to Graph Algorithms. Basics of
3 min read
Trie Data StructureThe Trie data structure is a tree-like structure used for storing a dynamic set of strings. It allows for efficient retrieval and storage of keys, making it highly effective in handling large datasets. Trie supports operations such as insertion, search, deletion of keys, and prefix searches. In this
15+ min read
Algorithms
Searching AlgorithmsSearching algorithms are essential tools in computer science used to locate specific items within a collection of data. In this tutorial, we are mainly going to focus upon searching in an array. When we search an item in an array, there are two most common algorithms used based on the type of input
2 min read
Sorting AlgorithmsA Sorting Algorithm is used to rearrange a given array or list of elements in an order. For example, a given array [10, 20, 5, 2] becomes [2, 5, 10, 20] after sorting in increasing order and becomes [20, 10, 5, 2] after sorting in decreasing order. There exist different sorting algorithms for differ
3 min read
Introduction to RecursionThe process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. A recursive algorithm takes one step toward solution and then recursively call itself to further move. The algorithm stops once we reach the solution
14 min read
Greedy AlgorithmsGreedy algorithms are a class of algorithms that make locally optimal choices at each step with the hope of finding a global optimum solution. At every step of the algorithm, we make a choice that looks the best at the moment. To make the choice, we sometimes sort the array so that we can always get
3 min read
Graph AlgorithmsGraph is a non-linear data structure like tree data structure. The limitation of tree is, it can only represent hierarchical data. For situations where nodes or vertices are randomly connected with each other other, we use Graph. Example situations where we use graph data structure are, a social net
3 min read
Dynamic Programming or DPDynamic Programming is an algorithmic technique with the following properties.It is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of
3 min read
Bitwise AlgorithmsBitwise algorithms in Data Structures and Algorithms (DSA) involve manipulating individual bits of binary representations of numbers to perform operations efficiently. These algorithms utilize bitwise operators like AND, OR, XOR, NOT, Left Shift, and Right Shift.BasicsIntroduction to Bitwise Algorit
4 min read
Advanced
Segment TreeSegment Tree is a data structure that allows efficient querying and updating of intervals or segments of an array. It is particularly useful for problems involving range queries, such as finding the sum, minimum, maximum, or any other operation over a specific range of elements in an array. The tree
3 min read
Pattern SearchingPattern searching algorithms are essential tools in computer science and data processing. These algorithms are designed to efficiently find a particular pattern within a larger set of data. Patten SearchingImportant Pattern Searching Algorithms:Naive String Matching : A Simple Algorithm that works i
2 min read
GeometryGeometry is a branch of mathematics that studies the properties, measurements, and relationships of points, lines, angles, surfaces, and solids. From basic lines and angles to complex structures, it helps us understand the world around us.Geometry for Students and BeginnersThis section covers key br
2 min read
Interview Preparation
Practice Problem