beginner · 32 minute study
Choose a data shape and follow the work it creates
Understand arrays, keyed lookups, uniqueness, algorithms and recursion well enough to recognize unnecessary work before optimizing blindly.
Useful preparation · 1 prerequisite
Use this as a map, not a lock. If these ideas are familiar, continue.
- Turn a rule into a small, testable contract — Move from copying blocks of code to naming a useful operation with clear inputs, outputs and failure behavior.
First, build a mental model
A collection organizes data for particular questions. An algorithm is a repeatable procedure over that data. Complexity asks how its work or memory grows when the input grows, not how impressive its syntax looks.
- An array preserves positions and order. A map connects keys to values. A set answers membership and uniqueness questions.
- A linear scan may inspect n items. Two full nested scans can inspect n × n pairs; a suitable keyed lookup can avoid repeated scans, subject to its actual implementation and cost.
- Recursion solves a smaller instance of the same problem. It needs a reachable base case and progress toward it.
- Each unfinished recursive call retains work on the call stack. This simple sum uses O(n) time and O(n) stack space; an iterative sum can avoid that growing stack.
- Big-O describes scaling, not exact milliseconds. Measure realistic input sizes and account for constants and runtime limits.
function sum(items, index = 0) {
if (index >= items.length) return 0;
return items[index] + sum(items, index + 1);
}
console.log(sum([2, 3, 4]));- Call 0
Keep 2 pending and ask for the sum beginning at index 1.
- Calls 1 and 2
Keep 3, then 4 pending while index moves toward the array length.
- Base case
At index 3, return 0. Unwind: 4 + 0, then 3 + 4, then 2 + 7 = 9.
Production thinking
Take this beyond the example.
Use the simplest data structure that fits the workload, then measure. Consider input bounds, allocation, repeated queries and stack depth; a fast-looking one-liner can hide substantial work.
Sources and further reading
Your evidence
unseen is a local learning signal, not a credential or proof of production competence.
Explain the mental model, then explicitly acknowledge it. Opening a page is not evidence.
Supported retries can complete this lesson. Independent evidence and delayed review determine the skill stage.
Next lesson · Model allowed changes, not just stored fields →