Pseudocode is a way of describing an algorithm through a mixture of programming constructs, ordinary language, and mathematical notation. In computer science, it communicates the steps of a computation without requiring the exact rules of a particular programming language. Its intended reader is usually a person rather than a computer. It occupies an intermediate position between an informal explanation and executable code, making operational details explicit while omitting syntax that is irrelevant to the algorithm being described. (cs.cornell.edu)
Purpose and scope
Pseudocode separates an algorithm’s essential decisions and operations from the details of its implementation. A description can specify which values are compared, which operations repeat, and what result is returned without committing to a particular language or development environment. This language independence makes it useful when the same algorithm may be implemented in several languages. (cs.utexas.edu)
The appropriate level of abstraction depends on the audience and purpose. A sorting algorithm being introduced for the first time needs its internal steps explained; another algorithm that uses sorting as an established operation may simply call a sorting subroutine. Abstraction becomes excessive when it hides the operations needed to understand or analyze the computation. Conversely, reproducing every implementation detail can obscure the main idea. (cs.cornell.edu)
Pseudocode also appears in software documentation. Design explanations can use it to describe complex algorithms alongside architectural decisions, boundary conditions, and invariants. It records how a computation is organized without necessarily reproducing its final source code. (cs.cornell.edu)
Notation and conventions
Pseudocode is not one universally prescribed language. Individual courses, textbooks, and examination systems establish conventions for their own purposes. Some descriptions closely resemble ordinary code, while others incorporate longer verbal instructions. Cambridge International, for example, publishes a guide specifying notation for its computer science examinations. Such a guide defines a particular dialect rather than rules binding all pseudocode. (cs.cornell.edu)
Typical descriptions use named variables, assignments, comparisons, and control flow constructs. An assignment such as count ← count + 1 updates a variable; it does not assert a mathematical equality. Conditional statements select between alternatives, and loops repeat a block of operations. Indentation or explicit closing keywords identify which statements belong together. (cambridgeinternational.org)
Common constructs include:
IF,ELSE, and related forms for conditional execution.FOR,WHILE, andREPEATfor iteration.- Named procedures and functions, with parameters.
RETURNfor delivering a function’s result.- Indexed access to an array or another data structure.
- Boolean conditions and operators such as
AND,OR, andNOT. (cambridgeinternational.org)
Readable syntax does not eliminate the need for precise semantics. A description must make consequential conventions understandable, including index bounds, loop stopping conditions, and whether an operation changes its arguments. Cambridge’s dialect explicitly distinguishes parameter passing by value and by reference. (cambridgeinternational.org)
Example: binary search
The following illustrative pseudocode expresses binary search over an array sorted in nondecreasing order. Indices begin at zero, and the return value NOT_FOUND indicates that no matching element exists. The notation floor means rounding down to an integer. The algorithm repeatedly examines the middle of the remaining search interval and discards the half that cannot contain the target. (cs.cornell.edu)
BINARY_SEARCH(A, target)
low ← 0
high ← length(A) - 1
WHILE low ≤ high
middle ← low + floor((high - low) / 2)
IF A[middle] = target
RETURN middle
ELSE IF A[middle] < target
low ← middle + 1
ELSE
high ← middle - 1
RETURN NOT_FOUND
In this version, both interval endpoints are inclusive. An empty array immediately fails the loop condition. If duplicate values occur, the procedure returns a matching index but does not promise the first or last occurrence. These properties follow from the example’s initialization, comparisons, and updates.
The example omits language-specific declarations and array APIs while retaining the decisions needed to implement the search. Its worst-case time complexity is logarithmic in the array length under the assumption that indexed access and comparisons take constant time. This is conventionally expressed using big O notation as . (cs.cornell.edu)
Correctness and analysis
Pseudocode can serve as the operational description around which a mathematical proof is organized. Preconditions state assumptions about the input, and postconditions state what the result must establish. Assertions describe properties expected to hold at particular points during execution. These statements supplement the algorithm rather than replace its steps. (cs.cornell.edu)
For iterative algorithms, a loop invariant connects successive iterations. In binary search, an invariant can state that any possible matching element remains within the current search interval. A correctness argument explains why initialization establishes this property, each iteration preserves it, and termination yields the required result. Termination also requires showing that the remaining interval decreases. (cs.cornell.edu)
Analysis concerns the described operations and their assumed costs, not merely the visual length of the listing. A compact instruction may conceal substantial computation. Pseudocode must therefore expose enough detail for meaningful complexity analysis. (cs.cornell.edu)
Educational use and limitations
Algorithm textbooks use pseudocode to present methods without making knowledge of one implementation language a prerequisite. Introduction to Algorithms, for example, describes algorithms in English and pseudocode intended for readers with some programming experience. In teaching and assessment, a shared notation also gives readers consistent expectations about how constructs are written. (mitpress.mit.edu)
Pseudocode alone is not a complete algorithmic explanation. MIT’s algorithms course guidance distinguishes a description of the algorithm from illustrative examples, a correctness argument, and running-time analysis. A listing can show what operations occur without establishing why they solve the problem or how efficiently they do so. (ocw.mit.edu)
References
- CS 341 (Algorithms): Pseudocodecs.cornell.edu
- Algorithmscs.utexas.edu
- CS 4120 Overview Documentation for Programming Assignmentscs.cornell.edu
- Cambridge International AS & A Level 9618 Computer Science Pseudocode Guide for Teachers for examination in 2026cambridgeinternational.org
- Loop invariantscs.cornell.edu
- Analyzing Complexitycs.cornell.edu
- CS2110. Program correctnesscs.cornell.edu
- Introduction to Algorithmsmitpress.mit.edu
- Syllabus: Introduction to Algorithms (SMA 5503)ocw.mit.edu