Algorithm dossier

  • Category: MST
  • Worst-case complexity: O(n log n)
  • Approach: Greedy
  • Data structure: DSU
  • First formalised: 1950s

Why this snippet is Kruskal's Algorithm

Why Kruskal. Two ingredients: sort edges by weight ascending, then walk them adding any edge whose endpoints belong to *different* components. Component tracking is union-find (p array with path compression in f). The minimum spanning tree falls out. vs. Prim. Prim grows the tree from a single vertex by repeatedly adding the cheapest *adjacent* edge; Kruskal grows a forest, merging components as cheap edges link them.

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.