Algorithm dossier

  • Category: Graph
  • Worst-case complexity: O(n)
  • Approach: Recursive
  • Data structure: Graph
  • First formalised: 1880s

Why this snippet is Depth-First Search

Why DFS. Recursive descent into each neighbour before backtracking. The recursion stack *is* the traversal stack — that's the LIFO that distinguishes DFS from BFS. Iterative variant. Same algorithm with an explicit stack.push/stack.pop instead of recursion; the recursive form is more readable but blows the stack on long chains (n ~ 10⁴ in Python without manual stack lifting).

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.