Algorithm dossier

  • Category: Sort
  • Worst-case complexity: O(n²)
  • Approach: Iterative
  • Data structure: Array
  • First formalised: 1950s

Why this snippet is Bubble Sort

Why bubble sort. Two nested loops, the inner index bounded by n - i - 1, the adjacent swap on a misorder. That n-i-1 is the give-away: each outer pass parks one more element at the high end, so the inner pass shrinks. Often confused with. Insertion sort — also quadratic, also adjacent-swap-y, but insertion sort scans *backwards* from a sentinel rather than forwards through a pairwise comparison.

How to read a redacted algorithm

Algodle strips identifier names so the snippet has to be read for its shape: the control flow, the data structures it manipulates, the order in which it visits its input. Loops with two pointers crawling toward each other are usually search or partition. A recursion that splits its input in half and recurses on both halves is divide-and-conquer. A priority queue plus graph traversal is almost certainly Dijkstra, Prim, or A*. Six hint columns — category, complexity, approach, data structure, era — let you triangulate even when the snippet itself is opaque.