Foundations: Algorithms, Approximation & Error

pseudocode

Pseudocode is a way of writing down an algorithm in plain, structured English (or any language) mixed with a little mathematical notation, so a human can read the logic without getting tangled in the syntax of a real programming language. It is the blueprint stage: you describe what to do step by step, without worrying yet about semicolons, types, or which library to call.

It uses the universal building blocks of any procedure — assignment (set x = 1), conditionals (if ... then ... else), loops (for i = 1 to n, or while not converged), and a clear input and output line — but stays deliberately informal. For instance, Newton's method in pseudocode reads: input f, f', x_0, tolerance tol, max iterations N; for k = 0 to N-1: set x_{k+1} = x_k - f(x_k)/f'(x_k); if |x_{k+1} - x_k| < tol then return x_{k+1}; end for; report failure to converge. Anyone can read that and translate it into Python, C, or Fortran.

Pseudocode matters because it separates the idea of a method from its implementation. Textbooks and papers state algorithms in pseudocode so they survive across languages and decades; you reason about correctness, cost, and stopping rules at this level before a single line of code is run. The discipline is to be precise enough that the steps are unambiguous, yet free enough that you are thinking about the mathematics, not the machine.

input: array a[1..n]; set s = 0; for i = 1 to n: set s = s + a[i]; end for; output s. This is the whole 'sum the array' algorithm — readable, language-free, and obviously O(n) work.

Pseudocode shows the logic and the cost at a glance, before any real code exists.

Pseudocode is not a runnable program — it has no fixed grammar and cannot execute. Beware that real floating-point arithmetic behaves differently from the exact-looking math in pseudocode.

Also called
pseudo-code假碼擬碼