Defining Algorithms: Pseudocode and Flowcharts
What Is an Algorithm?
An algorithm is a precise, step-by-step set of instructions for solving a problem. Every program you have ever run began as an algorithm. Before any code is written, a programmer must first design the logical steps the computer needs to follow. Getting those steps right — in the right order, with the right decisions — is the foundation of good software.
Algorithms are not the same as programs. A program is a specific implementation in a specific language. An algorithm is language-independent — the same logic can be expressed in pseudocode, as a flowchart, or as code in Python, Java or any other language. Your exam tests whether you can design, trace and evaluate algorithms, regardless of which language you prefer to code in.
A good algorithm must be unambiguous (each step has exactly one interpretation), finite (it must eventually stop), and effective (it must actually solve the problem it was designed for).
Pseudocode
Pseudocode is an informal notation that sits halfway between plain English and a real programming language. It is precise enough to be translated directly into code, but readable enough that a non-programmer can follow the logic. Your exam uses a set of specific pseudocode conventions — learn them so your algorithms are unambiguous.
The key pseudocode keywords you need are shown below. The exam paper prints them in lower case, and it ends a while loop with the word repeat. Capitals in your own answers are fine, as long as the logic is clear:
| Purpose | Pseudocode keyword | Example |
|---|---|---|
| Assignment | set | set total = 0 |
| Output to screen | output | output “Hello” |
| Input from user | input | input name |
| Set a data type | is | myvariable is integer |
| Conditional | if / else / end if | if score > 50 |
| Count-controlled loop | for / next | for i = 1 to 10 ... next i |
| Condition-controlled loop | while / repeat | while total < 100 ... repeat |
| Post-condition loop | repeat / until | repeat ... until done = TRUE |
| Define a subroutine | Declare / End Subroutine | Declare Greet ... End Subroutine |
| Call a subroutine | call | call Greet |
Below is a complete pseudocode algorithm that asks the user for three numbers and outputs their average. Each line maps directly to a keyword in the table above.
INPUT num1
INPUT num2
INPUT num3
SET total = num1 + num2 + num3
SET average = total / 3
OUTPUT “The average is ” & average
Notice: INPUT handles input, SET handles assignment, and OUTPUT sends text to the screen. The & operator joins (concatenates) a string and a number in the output.
Flowcharts
A flowchart shows exactly the same logic as pseudocode but as a visual diagram. Each shape has a fixed meaning. Arrows show the flow of control — which instruction comes next. You need to know five shapes:
| Shape | Name | Used for |
|---|---|---|
| Oval / rounded rectangle | Terminator | START and STOP of the algorithm |
| Rectangle | Process | Any calculation, assignment or output step |
| Parallelogram | Input / Output | Receiving data from the user or displaying a result |
| Diamond | Decision | A yes/no question — branches the flow |
| Rectangle with double side bars | Subroutine call | Calling a named subroutine or function |
Every flowchart must start and end with a terminator (oval). Decision diamonds always have exactly two exit arrows, typically labelled “Yes” and “No”. Process boxes have one entry and one exit arrow.
Many students write Python or JavaScript instead of pseudocode when the exam asks for an algorithm. Real code can score, but there are two risks. First, a syntax slip in Python can hide your logic, and a marker can only credit logic they can follow. Second, pseudocode is faster to write in exam conditions because you don’t worry about syntax errors.
Another common error is writing prose instead of pseudocode: “Ask the user for a number, add it to the total, and repeat.” This is not pseudocode — it has no control structure keywords and cannot be traced step by step. Always use the keywords: INPUT, SET, FOR, WHILE, IF.
Trace Tables
A trace table is used to check an algorithm by simulating it line by line. You create a column for every variable, plus an output column. Then you work through the algorithm and record the value of each variable after each step. Trace-table questions are a regular feature of the written exam — many students give only the final answer and lose intermediate marks.
Consider this algorithm:
SET total = 0
FOR i = 1 TO 3
SET total = total + i
NEXT i
OUTPUT total
Trace table:
| Line | i | total | Output |
|---|---|---|---|
| SET total = 0 | — | 0 | |
| i = 1, total = 0 + 1 | 1 | 1 | |
| i = 2, total = 1 + 2 | 2 | 3 | |
| i = 3, total = 3 + 3 | 3 | 6 | |
| OUTPUT total | 6 |
The answer is 6. Fill in every row — marks are awarded per row, not just for the final output.