The Runtime Theory
Programming & AlgorithmsPlanned

Learning Algorithms from Scratch

Video not available yet
12:00#beginner#algorithms#arrays#search

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

  1. "What is an algorithm?" text + recipe analogy
  2. Array memory layout: contiguous cells at 0x1000, 0x1004, 0x108
  3. Cache line animation: one fetch loads 16 cells
  4. Linear search: highlight each cell, show comparison result
  5. Array insertion: show resize → shift → write
  6. Side-by-side: array vs linked list memory comparison

Companion Material

Related articles

More in Programming & Algorithms

New 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.

Sign in to save