LLearnCode
Academy/foundations/Mental models that transfer

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.

Loading progressEvidence grows with practice
Useful preparation · 1 prerequisite

Use this as a map, not a lock. If these ideas are familiar, continue.

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.

  1. An array preserves positions and order. A map connects keys to values. A set answers membership and uniqueness questions.
  2. 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.
  3. Recursion solves a smaller instance of the same problem. It needs a reachable base case and progress toward it.
  4. 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.
  5. Big-O describes scaling, not exact milliseconds. Measure realistic input sizes and account for constants and runtime limits.
Read the codejavascript · educational example
function sum(items, index = 0) {
  if (index >= items.length) return 0;
  return items[index] + sum(items, index + 1);
}
console.log(sum([2, 3, 4]));
  1. Call 0

    Keep 2 pending and ask for the sum beginning at index 1.

  2. Calls 1 and 2

    Keep 3, then 4 pending while index moves toward the array length.

  3. 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 →