Algorithm dossier

  • Category: Tree op
  • Worst-case complexity: O(n)
  • Approach: Iterative
  • Data structure: Trie
  • First formalised: 1960s

Why this snippet is Trie Insertion

Why trie insertion. Walk the input string character-by-character down a nested dictionary. At each character, descend into the child keyed by that char — creating a new empty dict if it's missing. The terminal marker ('$': True here) signals "a word ends here." Why $. Without an end-of-word sentinel, you can't tell ["car", "card"] apart from ["card"] alone — "car" would be considered absent.

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.