Module 11 · Bits, Range Tools and Final Review · Lesson 39 of 40
The pattern map: which tool when?
Turn problem wording into the right data structure or pattern. A cheat sheet, a matching drill and flashcards.
In this lesson · about 20 minutes
- Match common problem clues to the right pattern
- Recall the cost of the main operations
- Follow a simple plan when you meet a new problem
A plan for any new problem
- Understand: say the problem in your own words. Try a tiny example by hand.
- Brute force first: what's the simplest correct idea, even if slow? What is its Big-O?
- Look for clues (table below) to find a faster pattern.
- Code it, then test small cases: empty input, one item, all the same, already sorted.
- State the cost: time and space.
Clue → pattern
| If the problem says… | Think of… |
|---|---|
| "Have I seen it?", count things, pair that adds to a target | Dict / set (hashing) |
| Sorted list, find a pair, palindrome, in place | Two pointers |
| Subarray / substring, longest / shortest, "k in a row" | Sliding window |
| Many range-sum questions | Prefix sums |
| Sorted data, or "smallest x that works" | Binary search |
| Brackets, undo, "next greater" | Stack / monotonic stack |
| Process in arrival order, levels, fewest steps | Queue / BFS |
| Hierarchy, parent and children | Tree + recursion (DFS) |
| "k largest", "k smallest", always the best next item | Heap |
| Network, map, connections, dependencies | Graph: BFS, DFS, Dijkstra, topological sort |
| Groups that merge | Union-find |
| Prefixes of words, autocomplete | Trie |
| All combinations / arrangements | Backtracking |
| Number of ways, min cost, max value with overlapping choices | Dynamic programming |
| Intervals, schedules, "always take the best now" (proven) | Greedy (often after sorting) |
| Pairs cancel out, powers of two, small sets | Bit manipulation |
Sorting drill
Pick the pattern
Each problem below has a clue. Put it under the pattern that fits best.
- Find the first word that appears twice in a book
- Longest stretch of a string with no repeated letter
- Check if every ( has a matching )
- Fewest moves for a knight to reach a square
- Number of ways to make 50 cents from coins
- Two numbers in a sorted list that add up to 100
- Group words that are anagrams of each other
- Can I get from city A to city B at all?
- Serve customers in the order they arrived
- Most money from houses, no two neighbours
0 of 10 sorted
Flashcards
Costs to remember
0 of 14 known
Say the Big-O out loud before flipping.
14 left in the deck
Check your understanding0 of 2 correct
Quiz score: 0 of 2
Tip: answer every quiz question correctly first.
Noviq Academy is free and for learning. This course follows the topics of a set of DSA study notes, rewritten in Noviq's own words with Python examples. Python runs in your own browser with Pyodide; nothing you type is sent to Noviq.