VOOZH about

URL: https://www.geeksforgeeks.org/dsa/what-is-pseudocode-a-complete-tutorial/

⇱ What is PseudoCode - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

What is PseudoCode

Last Updated : 21 Feb, 2026

Pseudocode is a step-by-step description of an algorithm written in simple English using a code-like structure.
It is designed for human understanding, not for machine execution, and does not follow the syntax of any programming language.

Why Do We Need Pseudocode:

  • Helps programmers plan the solution before writing actual code
  • Makes the logic easy to understand for others reading the solution
  • Bridges the gap between algorithm design and coding
  • Reduces logical errors before implementation
👁 Pseudocode is an intermediate state between algorithm and 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 tasks logically and write steps in sequence.
  • Define the goal first.
    Example:
    This program prints the first N Fibonacci numbers.
  • Use standard programming constructs:
    • IF–ELSE
    • FOR
    • WHILE
  • Indent blocks properly to improve readability and clarity.
  • Use clear and meaningful names for variables and steps.
  • Write keywords in CAPITAL letters (IF, ELSE, WHILE).
  • Ensure the pseudocode is:
    • Complete
    • Finite
    • Easy to understand
  • Avoid writing actual programming syntax—keep it simple and language-independent.

Good vs Bad ways of writing Pseudocode:

👁 Good Vs Bad way of writing Pseudocode
Good Vs Bad way 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.

Below is the pseudocode for Binary search.

BINARY_SEARCH(ARR, X, LOW, HIGH)

WHILE LOW ≤ HIGH

MID = (LOW + HIGH) / 2

IF ARR[MID] == X

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 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

Comment
Article Tags:
Article Tags: