Skip to main content
Data Structures & Algorithms · Chapters

Introduction to data structures & algorithms

Good problem solving starts with knowing what to keep, what to discard, and how much work each decision costs.

You have a list of events and need to find one timestamp. A search works, but which search? That depends on whether the list is sorted, whether it changes, and how often you need an answer. Choosing an algorithm begins with those details.

This subject builds the tools for making that choice. You’ll follow small examples, trace the code, and work through the edge cases that turn a plausible solution into a correct one.

What does a good solution need?

A precise input and output, an explanation of why the result is correct, and an honest account of the time and extra memory it uses. A short piece of code can still do a great deal of work.

What you’ll learn

Begin with cost models and binary search. Then work through arrays, hashing and linked structures before moving on to trees, graphs and dynamic programming. You can read the sequence or jump to a familiar topic in the sidebar.

Before you begin

Comfort with variables, loops, functions and arrays in one language. The examples use JavaScript; the reasoning transfers to other languages.

You can read everything for free. Worked examples, practice questions and relevant interactive exercises are included in the chapter where you need them.

How to practise

For each example, predict the next state before reading it. Try an empty input, a repeated value and a case with no answer. Write down the invariant—the fact your algorithm keeps true—before changing the code.

Try each exercise before opening its explanation. If an update surprises you, trace a smaller example. The goal is to make the reasoning your own.