Pseudocode

“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.”

Guidelines for Writing Pseudocode:

  1. Use Plain Language:
    • Write in simple, plain language that describes the steps of your algorithm.
    • Avoid specific programming syntax; focus on the logic and flow.
  2. Structure and Indentation:
    • Use indentation to show hierarchy.
    • This makes your pseudocode easier to read and understand.
  3. One Statement per Line:
    • Write only one statement or action per line to keep it clear and concise.
  4. Use Keywords:
    • Incorporate common programming keywords like IF, ELSE, WHILE, FOR, END, etc.
    • Capitalize these keywords to distinguish them from other text.
  5. Be Consistent:
    • Maintain a consistent style throughout your pseudocode.
    • This helps in understanding and translating it into actual code.
  6. Comments and Explanations:
    • Include comments or explanations if a step is complex or not immediately clear.
    • This helps others (or yourself) understand the logic later.

Example of Pseudocode:

Pseudocode for finding the largest number in a list:

BEGIN

SET largest TO first element of the list

FOR each element in the list

IF element > largest THEN

SET largest TO element

END IF

END FOR

DISPLAY “The largest number is: ” + largest

END

Rules of Pseudocode:

  1. Start and End:
    • Clearly define the start and end of your pseudocode with BEGIN and END.
  2. Control Structures:
    • Use control structures like loops (WHILE, FOR) and conditionals (IF, ELSE) to outline the flow of your algorithm.
  3. Variables and Operations:
    • Use simple variable names and basic operations (e.g., SET, ADD, SUBTRACT).
  4. Clarity and Simplicity:
    • Aim for clarity and simplicity. The goal is to make the logic easy to follow.
  5. No Syntax Rules:
    • Unlike actual code, pseudocode does not have strict syntax rules. It should be understandable by anyone familiar with programming concepts.