What is an Algorithm?

What is an Algorithm?

An algorithm is a finite, ordered set of well-defined instructions that takes input, performs computations, and produces output to solve a specific problem. Algorithms are the backbone of software—from sorting lists to routing traffic—and are evaluated by correctness, performance (time/space), and clarity.


Editorial note: This page aims to explain algorithms clearly for a global audience. It focuses on conceptual understanding, common types, real-world uses, and basic performance analysis. For code implementations and advanced topics, see the “Further reading” section. Clarifypedia maintains neutral, sourced content and updates when major advancements or consensus changes occur.


Definition

An algorithm is a precise set of instructions that describes how to perform a computation or solve a problem. Each step is unambiguous, the algorithm halts after a finite number of steps for valid inputs, and produces an output.

Formal properties:

  • Finiteness: Must complete after a limited number of steps.
  • Definiteness: Every step must be clearly defined.
  • Input: Zero or more inputs from a specified set.
  • Output: At least one output that is the solution/result.
  • Effectiveness: Steps are simple enough to be carried out, in principle, by a human or machine.

Key characteristics of an algorithm

  • Deterministic vs. Nondeterministic: Deterministic algorithms produce the same result given the same input. Nondeterministic or randomized algorithms can produce different behaviors (e.g., randomized quicksort pivot choice).
  • Termination: Correct algorithms must halt for all valid inputs.
  • Generality: An algorithm should solve not just one instance but a whole class of problems.

Common types of algorithms

  • Sorting: e.g., QuickSort, MergeSort, HeapSort, Bubble Sort.
  • Searching: e.g., Binary search, Linear search.
  • Graph algorithms: e.g., Dijkstra, A*, Bellman-Ford, BFS, DFS.
  • Dynamic programming: e.g., Knapsack, Longest Common Subsequence.
  • Greedy algorithms: e.g., Kruskal, Prim, Huffman coding.
  • Divide and conquer: e.g., MergeSort, QuickSort.
  • Randomized algorithms: e.g., Randomized QuickSort, Monte Carlo methods.
  • Approximation algorithms: For NP-hard problems when exact solutions are expensive.
  • Machine learning algorithms: e.g., gradient descent (optimization), decision trees.

How we measure algorithms: correctness & complexity

Correctness means the algorithm returns the expected result for all valid inputs.

Time complexity estimates how the runtime grows with input size n. We use asymptotic notation (Big O) to describe upper bounds.

Space complexity measures additional memory used (besides input storage).

Common complexity classes:

  • O(1) constant time
  • O(log n) logarithmic
  • O(n) linear
  • O(n log n) linearithmic
  • O(n^2) quadratic
  • O(2^n) exponential

Practical note: Constant factors and low-order terms matter in real-world code—benchmarks complement theoretical analysis.


Example: Sorting algorithm (Bubble Sort)

What it does: Repeatedly steps through a list, compares adjacent elements, and swaps them if they are in the wrong order. Continue until the list is sorted.

Pseudocode:

function bubbleSort(array A):
    n = length(A)
    for i from 1 to n-1:
        swapped = false
        for j from 0 to n-i-1:
            if A[j] > A[j+1]:
                swap A[j] and A[j+1]
                swapped = true
        if not swapped:
            break
    return A

Real-world applications

  • Search engines: Ranking algorithms and indexing.
  • Navigation & maps: Shortest-path algorithms (e.g., Dijkstra, A*).
  • Compression & encryption: Huffman coding, cryptographic algorithms.
  • E-commerce & personalization: Recommendation algorithms and collaborative filtering.
  • Finance: Trading algorithms, risk models, and fraud detection.
  • Robotics & control: Path planning and control loops.

Basic algorithm design techniques

  1. Brute force: Try all possible solutions—simple but often slow.
  2. Greedy: Make the locally optimal choice at each step.
  3. Divide and conquer: Split problem into subproblems, solve them, then combine results.
  4. Dynamic programming: Save results of subproblems to avoid recomputation.
  5. Backtracking: Explore possibilities and abandon unpromising ones.
  6. Randomized methods: Use randomness to simplify or speed up solutions.

Common algorithmic problems & resources

  • Sorting and searching
  • Graph traversal and shortest paths
  • String matching (e.g., KMP)
  • Combinatorial optimization (e.g., traveling salesman)
  • NP-complete problems and approximations

Suggested resources: textbooks (CLRS), reputable online courses (Coursera, edX), and algorithm problem sites (LeetCode, HackerRank).


Images & media suggestions:

  1. Diagram: Flowchart of a simple algorithm (alt: “Flowchart showing algorithm steps”).
  2. Visual: Big O complexity chart (alt: “Big O complexity comparison chart”).
  3. Animated GIF: Sorting visualization (alt: “Visualization of Bubble Sort comparing and swapping elements”).

Image file names & alt-text examples:

  • flowchart-algorithm.png — “Flowchart of an algorithm showing input, steps, and output”
  • big-o-chart.png — “Chart comparing Big O time complexities”
  • bubble-sort-animation.gif — “Animation of Bubble Sort swapping adjacent elements”

Structured data (JSON-LD) — Article schema (example):

{
  "@context": "https://schema.org",
  "@type": "Article",
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "https://clarifypedia.com/what-is-algorithm"
  },
  "headline": "What is an Algorithm? — Definition, Examples & Complexity",
  "description": "An algorithm is a step-by-step procedure for solving a problem or performing a task. Learn types, complexity, examples and real-world uses.",
  "image": "https://clarifypedia.org/assets/images/what-is-algorithm/flowchart-algorithm.png",
  "author": {"@type": "Organization", "name": "Clarifypedia"},
  "publisher": {"@type": "Organization", "name": "Clarifypedia", "logo": {"@type": "ImageObject", "url": "https://clarifypedia.org/assets/images/logo.png"}},
  "datePublished": "2025-12-31",
  "dateModified": "2025-12-31"
}

Canonical & Open Graph metadata (recommended in page head):

<link rel="canonical" href="https://clarifypedia.com/what-is-algorithm">
<meta property="og:title" content="What is an Algorithm? — Definition, Examples & Complexity">
<meta property="og:description" content="An algorithm is a step-by-step procedure for solving a problem or performing a task. Learn types, complexity, examples and real-world uses.">
<meta property="og:url" content="https://clarifypedia.org/what-is-algorithm">
<meta property="og:type" content="article">
<meta property="og:image" content="https://clarifypedia.org/assets/images/what-is-algorithm/flowchart-algorithm.png">

Accessibility: Use semantic HTML headings, HTML lists, ARIA landmarks, and descriptive alt text.


Last updated

December 31, 2025 — Clarifypedia editorial review.


Clarifypedia