Algorithm dossier

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

Why this snippet is Insertion Sort

Why insertion sort. Two loops, but the inner one walks *backwards*, sliding everything > x right by one slot until the gap fits. Bubble sort would have done pairwise compare-and-swap forward; selection sort would have scanned for a minimum first. Why it's still useful. It's O(n) on already-sorted input — the inner for j exits immediately — so it underpins Timsort's run-by-run finishing pass.

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.