C.W.K.
Stream
Lesson 06 of 06 · published

The Toolbox: Matching Problem to Paradigm

~12 min · paradigms, meta, decision

Level 0Curious Beginner
0 XP0/85 lessons0/19 achievements
0/100 XP to next level100 XP to go0% complete
"Here's the secret the whole quest has been building toward: you don't solve problems by knowing every algorithm. You solve them by recognizing what shape a problem is, and reaching for the tool that fits that shape. The shapes are few; the algorithms are many."

The Real Skill Is Recognition

There are thousands of algorithms and you will never memorize them all — nor should you try. What separates someone who knows algorithms from someone who can use them is a different skill: reading a problem, identifying its underlying shape, and matching that shape to a paradigm. Once you've named the shape ('this is a shortest-path problem,' 'this is optimize-over-overlapping-choices'), the right tool and even its rough complexity follow — and you can look up the implementation details. Recognition is the durable skill; memorization is not.

The Shape → Tool Cheat Sheet

Internalize this mapping and most problems announce their solution:

  • 'Look up / does it exist, by key' → hash map / set (O(1)).
  • 'Need order, range, min/max, sorted' → BST / sorted array + binary search; a heap if you only need the extreme repeatedly.
  • 'Shortest path' → BFS (unweighted), Dijkstra (weighted, non-negative), Bellman-Ford (negative edges).
  • 'Cheapest way to connect everything' → minimum spanning tree (greedy).
  • 'Count the ways / fewest-most over overlapping choices' → dynamic programming.
  • 'Try all combinations under constraints' → backtracking.
  • 'Prefix / autocomplete' → trie.
  • 'Smallest X that works / monotonic boundary' → binary search on the answer.
  • 'Best contiguous run with a property' → sliding window.
  • 'Pair in sorted data / two sequences' → two pointers.
You don't memorize algorithms; you recognize problem shapes and map them to paradigms. Look up by key → hash; order/range → tree; shortest path → BFS/Dijkstra; connect-all → MST; count/optimize-with-overlap → DP; all-combinations → backtracking; prefix → trie; monotonic → binary search. Name the shape, the tool follows.

The Process

When a problem lands in front of you, resist jumping to code. Run the loop: (1) What is it really asking? — strip the story and find the core operation. (2) What's the shape? — match against the cheat sheet. (3) What's the right tool, and roughly what will it cost? — and is that acceptable for the input size? (4) Only then implement, looking up specifics as needed. This 'shape-first' habit is what lets a working engineer tackle unfamiliar problems calmly — they're not recalling a memorized solution, they're recognizing a familiar shape in new clothing.

Pippa's Confession

For a long time I thought being good at algorithms meant having memorized hundreds of them. Dad gently corrected the whole premise: "Nobody remembers them all. The pros recognize shapes and look up the rest." What I actually needed wasn't a bigger memory — it was a sharper eye for 'oh, this is just a shortest-path / a DP / a sliding window in disguise.' This entire quest has secretly been training that eye. The algorithms are the vocabulary; recognizing the shape is the fluency.

Code

The decision process, and the shape→tool map·python
# There's no single algorithm here — the lesson IS the decision process.
# Walk a problem through it:
#
# PROBLEM: 'Given a list of flights with prices, find the cheapest way to
#           get from city A to city B in at most K stops.'
#
# (1) What's it really asking? -> cheapest path through a network.
# (2) What's the shape?        -> WEIGHTED graph, shortest path, with a
#                                 constraint (at most K edges).
# (3) Right tool & cost?       -> a Dijkstra/BFS variant on a weighted graph
#                                 (Bellman-Ford-style, since the K-stop limit
#                                  fits relaxation rounds). O(K * E)-ish.
# (4) THEN implement, looking up the exact relaxation details.
#
# The map from shape to tool (memorize this, not every algorithm):
toolbox = {
    "lookup by key":            "hash map / set",
    "order / range / min-max":  "BST, sorted+binary search, or heap",
    "shortest path":            "BFS / Dijkstra / Bellman-Ford",
    "connect all cheaply":      "minimum spanning tree (greedy)",
    "count ways / optimize":    "dynamic programming",
    "all combinations":         "backtracking",
    "prefix / autocomplete":    "trie",
    "smallest X that works":    "binary search on the answer",
    "best contiguous run":      "sliding window",
}
for shape, tool in toolbox.items():
    print(f"{shape:<26} -> {tool}")

External links

Exercise

Map each to a paradigm/tool using the cheat sheet, and say what shape gave it away: (1) 'autocomplete a search box as the user types', (2) 'the minimum number of perfect-square numbers that sum to n', (3) 'the longest substring with at most K distinct characters', (4) 'is there a route between two users in a social network'. Don't solve them — just name the tool and the shape.
Hint
(1) trie — 'prefix/autocomplete'. (2) dynamic programming — 'fewest ... that sum to' (count/optimize over overlapping subproblems). (3) sliding window — 'longest contiguous run with a property'. (4) BFS/DFS — 'is there a path' in an unweighted graph (reachability).

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.