Learning Algorithms from Scratch
Lesson Promise
By the end of this lesson, you will understand what an algorithm actually is, why arrays give you O(1) indexing, and how a linear search or array insertion really executes in memory. No prior knowledge required.
Narration Draft
Part 1 — What Is an Algorithm? (2:00) An algorithm is a precise, step-by-step procedure for solving a problem. Think of a recipe: given ingredients (input), follow steps, get a dish (output). We look at pseudocode as a way to describe algorithms without worrying about syntax.
Part 2 — Arrays and Memory (4:00)
An array stores elements contiguously. The CPU computes address = base + index × size in one cycle — that is why indexing is O(1). A cache line fetches 16 adjacent integers at once, which is why sequential access is fast. Visual: draw memory from 0x1000 to 0x1020, show how array[3] is computed.
Part 3 — Tracing a Linear Search (3:00) Walk through searching for 7 in [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]. Show each element being read, each comparison, and why the worst case is O(n).
Part 4 — Tracing an Array Insertion (3:00) Show inserting 35 at index 2 in a full array. First resize (5→10), then shift three elements right, then write the new value. Contrast with linked list insertion where only two pointers change.
Visual Sequence
- "What is an algorithm?" text + recipe analogy
- Array memory layout: contiguous cells at 0x1000, 0x1004, 0x108
- Cache line animation: one fetch loads 16 cells
- Linear search: highlight each cell, show comparison result
- Array insertion: show resize → shift → write
- Side-by-side: array vs linked list memory comparison
Companion Material
Related articles
What Is an Algorithm?
A precise, step-by-step procedure for solving a problem or completing a task, illustrated with pseudocode and real-world analogies.
Arrays and Memory: How Indexing Works
Why array indexing is O(1), how the CPU computes element addresses, and what spatial locality means for performance.
Recursion: Functions Calling Themselves
How a function can solve a problem by delegating a smaller version of the same problem to itself, the call stack, and common pitfalls.
More in Programming & Algorithms
Advanced Algorithms: Sorting, Graphs, and Dynamic Programming
Master sorting, graph traversal, and dynamic programming through execution traces that reveal the mechanics behind the algorithms.
DetailsData Structures and Algorithms: From Arrays to Trees
Master arrays, hash tables, trees, and recursion through execution traces that show what actually happens in memory.
DetailsWhy Big-O Does Not Predict Every Run
A planned visual lesson connecting algorithmic growth to input shape, memory access, branches, and measured runtime.
DetailsNew lessons by email
Get new articles and notes on the systems behind everyday software.
One technical dispatch per week. No noise.
Not started
Sign in to save your learning progress.