foundation
Algorithms
Sorting, searching, traversal, recursion, dynamic programming, greedy choices, and graph algorithms.
Algorithm questions reward recognizing patterns before memorizing implementations. Sorting and searching set preconditions — sorted input, monotonic predicate, or unweighted edges. Two pointers and sliding window eliminate repeated scans when movement rules are monotonic. Prefix sums turn range queries into O(1) differences. Recursion and backtracking explore choice trees. Dynamic programming applies when subproblems overlap and optimal answers compose from smaller optimal answers. Greedy works only with proof.
Trade-off: compare time, memory, and implementation complexity before committing to a structure or pattern.
On interviews: name the pattern, state preconditions, give time and space, and compare one alternative approach.
Common pitfalls: forcing DP when a hash map or greedy pattern suffices; coding before stating invariants; ignoring stack depth on recursive solutions.
Checklist:
- Identify the pattern family.
- Prove preconditions.
- Estimate time and space.
- Use child topics for technique depth.