What pseudocode is
Pseudocode is a way of writing out the logic of an algorithm — a step-by-step procedure for solving a problem — in structured, readable English rather than in the exact syntax of Python, Java or C. It sits between a plain description and real code: more precise than prose, but free of the semicolons, brackets and library calls that distract from the logic. Its purpose is to let you (and your reader) reason about what the algorithm does before worrying about how a particular language expresses it.
There is no single official standard for pseudocode, which surprises students. Different textbooks and exam boards use slightly different keywords and conventions. What matters is that your pseudocode is clear, consistent and unambiguous — that a competent programmer could implement it in any language without guessing your intent. Pick a convention (or follow your module’s) and apply it consistently.
Why and when you’ll use pseudocode
Pseudocode is used to plan a program before coding, to communicate an algorithm in a report or exam where language-specific code would be noise, and to analyse an algorithm’s logic and efficiency independently of any language. In computer-science assignments you will be asked to design an algorithm and express it in pseudocode, to trace or ‘dry-run’ pseudocode by hand, or to explain how a piece of code works.
It is also a thinking tool: writing pseudocode first forces you to get the logic right before you get tangled in syntax, which is why experienced developers sketch it for non-trivial problems. For assessment, clear pseudocode demonstrates that you understand the algorithm itself, not just that you can make a particular language compile.
Pseudocode conventions and keywords
Although conventions vary, a widely understood set of keywords includes: BEGIN and END to bound the algorithm; INPUT (or READ) and OUTPUT (or PRINT/DISPLAY) for data in and out; the assignment arrow or SET…TO for giving a variable a value; IF…THEN…ELSE…ENDIF for decisions; WHILE…ENDWHILE and REPEAT…UNTIL for condition-controlled loops; and FOR…ENDFOR for count-controlled loops. Indentation is used to show which statements sit inside a loop or branch.
Write keywords in capitals so they stand out from variable names, indent the body of every loop and branch, and close each structure (ENDIF, ENDWHILE, ENDFOR) so the boundaries are unambiguous. These small disciplines are exactly what makes pseudocode readable — and what markers check.
The three control structures
Every algorithm, however complex, is built from just three control structures — a powerful idea from structured programming. Sequence is simply doing steps one after another, in order. Selection is making a decision — doing one thing or another depending on a condition (IF/ELSE, or CASE/SWITCH for many options). Iteration is repetition — doing something repeatedly while or until a condition holds (WHILE, REPEAT, FOR).
Recognising that any procedure decomposes into these three building blocks makes algorithm design tractable: you ask, at each point, ‘do I do this in order, choose between options, or repeat something?’ Choosing the right loop matters — use FOR when you know how many times to repeat, WHILE when you repeat until a condition changes, and REPEAT…UNTIL when the body must run at least once.
Worked example 1: find the largest number in a list
A simple algorithm that uses input, sequence, iteration and selection:
BEGIN
INPUT list of numbers
SET max TO first item in list
FOR each number in list
IF number > max THEN
SET max TO number
ENDIF
ENDFOR
OUTPUT max
END
Read it aloud and it is unambiguous: start by assuming the first item is the largest, then look at each number and update the maximum whenever you find a bigger one, and finally output the result. Note the capitalised keywords, the indentation inside the FOR loop, and the closing ENDIF and ENDFOR — those make the structure clear at a glance.
Worked example 2: bubble sort
A classic sorting algorithm that nests iteration and selection — and a favourite in assignments:
BEGIN
INPUT array A of n numbers
FOR i FROM 0 TO n-2
FOR j FROM 0 TO n-2-i
IF A[j] > A[j+1] THEN
SWAP A[j] AND A[j+1]
ENDIF
ENDFOR
ENDFOR
OUTPUT A
END
The inner loop repeatedly compares adjacent elements and swaps them if they are out of order, so the largest ‘bubbles’ to the end on each pass; the outer loop repeats this for every element. Being able to write, trace and explain an algorithm like this in pseudocode — and then discuss its efficiency — is exactly what such assignments assess.
Pseudocode versus flowcharts
Pseudocode and flowcharts are two ways of expressing the same algorithmic logic. A flowchart is a diagram using standard symbols — ovals for start/end, rectangles for processes, diamonds for decisions, parallelograms for input/output — connected by arrows showing the flow of control. Pseudocode is textual; flowcharts are visual.
Each has strengths. Flowcharts make the flow of control vivid and are excellent for explaining a simple algorithm to a non-technical reader, but they become unwieldy for anything large. Pseudocode scales much better to complex logic and translates more directly into real code. Many assignments ask for both: a flowchart to show the shape of the solution and pseudocode to express it precisely. Use the same logic in each so they agree.
Explaining algorithm efficiency (Big-O)
Designing an algorithm is only half the task; assignments often ask you to analyse its efficiency using Big-O notation, which describes how the running time (or memory) grows as the input size n grows. Common classes, from best to worst, include O(1) constant time, O(log n) logarithmic (as in binary search), O(n) linear (a single pass, like finding the maximum above), O(n log n) (efficient sorts such as merge sort) and O(n²) quadratic (nested loops, as in the bubble sort above).
To analyse pseudocode, look at the loops: a single loop over n items is O(n); two nested loops over n items is O(n²). Bubble sort’s nested loops make it O(n²), which is why it is inefficient for large inputs compared with an O(n log n) sort. Discussing complexity shows you can reason about how well an algorithm scales, not just whether it works — a key marking criterion in algorithms modules.
The most common pseudocode mistakes
- Writing real code instead of pseudocode. Drop language-specific syntax; focus on clear logic.
- Being ambiguous. A reader should not have to guess your intent; state each step explicitly.
- Inconsistent keywords or no closing statements. Always close IF/WHILE/FOR with ENDIF/ENDWHILE/ENDFOR.
- No indentation. Indent loop and branch bodies so the structure is visible.
- Choosing the wrong loop. FOR for known counts, WHILE for condition-controlled repetition, REPEAT…UNTIL when the body must run at least once.
- Ignoring efficiency. Where asked, analyse complexity with Big-O, not just correctness.
Worked example 3: binary search
Binary search finds a target in a sorted list far faster than checking every item, and it shows iteration and selection working together:
BEGIN
INPUT sorted array A of n numbers, target value T
SET low TO 0
SET high TO n-1
WHILE low <= high
SET mid TO (low + high) DIV 2
IF A[mid] = T THEN
OUTPUT mid // found at this index
STOP
ELSE IF A[mid] < T THEN
SET low TO mid + 1
ELSE
SET high TO mid - 1
ENDIF
ENDWHILE
OUTPUT "not found"
END
Each pass halves the search range, so binary search runs in O(log n) time — dramatically faster than the O(n) linear search for large lists. Note how the pseudocode makes the logic clear without committing to any language, and how the comment clarifies intent. The key precondition — the list must already be sorted — is exactly the sort of detail a marker looks for you to state.
How to trace (dry-run) pseudocode
Assignments frequently ask you to trace or ‘dry-run’ an algorithm: work through it by hand to show what happens at each step. The technique is to build a trace table with a column for each variable and a row for each step, then step through the pseudocode updating the values exactly as the computer would. For the find-maximum example, you would track max and the current number as the loop runs, showing how max changes only when a larger value appears.
Tracing proves you understand the algorithm’s behaviour, not just its shape, and it is the best way to find logic errors before you code. It also demonstrates to a marker that you can follow control flow precisely — including edge cases such as an empty list or a target that is not present. Practising tracing is one of the most reliable ways to improve at algorithms, because it forces you to think exactly as the machine does.
Decomposition and modular design
Real problems are rarely solved in one block of pseudocode. A core skill is decomposition — breaking a large problem into smaller, self-contained sub-problems — and expressing each as a subroutine (a procedure or function) that you can call by name. In pseudocode you might write CALL CalculateAverage(scores) and define CalculateAverage separately, with its own inputs and a returned value.
Modular design makes pseudocode easier to read, test and reuse, and it mirrors how real software is structured. In an assignment, showing that you can decompose a problem and define clear subroutines — each doing one thing, with well-named parameters — demonstrates higher-order design thinking beyond simply getting an algorithm to work. It also keeps your main algorithm short and readable, with the detail pushed down into named procedures, which is exactly the structure markers reward in larger problems.
Stuck on an algorithm or pseudocode assignment? Our computer-science writers design algorithms, write clear pseudocode and explain complexity to your brief.
Related guides
- Computer science assignment help (subject hub)
- Programming assignment help
- 200 computer science dissertation topics
Frequently asked questions
Is there an official standard for pseudocode?
No. Pseudocode has no single agreed standard, so keywords and conventions vary between textbooks and exam boards. What matters is that your pseudocode is clear, consistent and unambiguous enough for anyone to implement in any language. Follow your module’s convention where one is given.
What are the three control structures?
Sequence (steps in order), selection (decisions, using IF/ELSE or CASE) and iteration (repetition, using WHILE, REPEAT or FOR). Every algorithm, however complex, is built from these three building blocks.
What is the difference between pseudocode and a flowchart?
Both express the same algorithmic logic. Pseudocode is textual and scales well to complex logic and to real code; a flowchart is a diagram that makes the flow of control visual and is best for simpler algorithms. Assignments often ask for both.
When should I use a WHILE loop versus a FOR loop?
Use a FOR loop when you know in advance how many times to repeat (a count-controlled loop), and a WHILE loop when you repeat until a condition changes (condition-controlled). Use REPEAT…UNTIL when the body must run at least once before the condition is checked.
What is Big-O notation?
Big-O describes how an algorithm’s running time or memory grows as the input size n grows — for example O(n) linear, O(n log n) for efficient sorts, or O(n²) for nested loops like bubble sort. It lets you compare how well algorithms scale, independent of language or hardware.
Can someone help with my algorithm or pseudocode assignment?
Yes — our computer-science writers design algorithms, write clear pseudocode, produce flowcharts and explain complexity to your brief. See our computer science assignment help page or place an order.
Need an algorithm designed, written in pseudocode and explained by a computer-science specialist? Place an order or explore our computer science assignment help — rated 4.4/5 across 871 verified Trustpilot and Sitejabber reviews.