The Runtime Theory
Programming & Algorithms

What Is an Algorithm?

A precise, step-by-step procedure for solving a problem or completing a task, illustrated with pseudocode and real-world analogies.

The Runtime Theory Team6 min read#algorithms#pseudocode#beginner
▸ On this page

What Is an Algorithm?

An algorithm is a precise, step-by-step procedure for solving a problem or completing a task. It takes an input, follows a defined sequence of steps, and produces an output.

Think of a recipe: given ingredients (input), follow the steps, and you get a dish (output). A GPS navigation system is an algorithm too: given a starting point and destination (input), it computes a route (output).

What Makes a Good Algorithm?

  1. Correct — it produces the right answer for all valid inputs.
  2. Finite — it terminates and does not loop forever.
  3. Precise — each step is unambiguous; no room for interpretation.
  4. Efficient — it uses a reasonable amount of time and memory.

Pseudocode

Pseudocode describes algorithms in a human-readable format, without worrying about syntax of any particular programming language. It uses conventions like if, for, while, and assignment (=).

plaintext
Algorithm: LinearSearch(array, target)
  for i = 0 to length(array) - 1
    if array[i] == target
      return i
  return -1

Examples of Algorithms

ProblemAlgorithmTime Complexity
Find an item in a listLinear searchO(n)
Find an item in a sorted listBinary searchO(log n)
Sort a listMerge sortO(n log n)
Find the shortest pathDijkstra'sO((V + E) log V)

See how a linear search executes step by step.

The Cost of an Algorithm

Every algorithm takes time and memory. We measure this with Big-O notation, which describes how the cost grows as the input size increases:

  • O(1) — constant time, regardless of input size
  • O(log n) — grows slowly; doubles in input only adds one step
  • O(n) — grows linearly; doubles in input doubles the steps
  • O(n²) — grows quadratically; doubles in input quadruples the steps

Read more about complexity analysis.

Try It Yourself

Implement binary search puts these ideas into code.


This article is the first step in the Algorithms Foundations learning path.

Not started

Sign in to save your learning progress.

Sign in to save