2  How to Use This Book

3 How to Use This Book

If you skipped the preface, here are the three things you need to know before chapter 1.

3.1 1. Every chapter is one lecture

There are forty chapters: twenty for CSS 342, twenty for CSS 343. Each is a 120-minute lecture compressed into reading form. Each chapter follows the same skeleton:

Warmup (LeetCode problem)
Learning objectives
Core concepts (with code)
Common mistakes
Try-it exercises
Self-check quiz
Challenges (3–5 LeetCode problems)
Where this fits in the course

You can read a chapter in 30–60 minutes if you do not write any code, or in 3–4 hours if you do. Write the code.

3.2 2. The conventions in code blocks

Every code block in this book is real, compilable C++. The signal-to-noise rules:

// Comments that begin with regular text explain what the next block does.

// cout << "lo: " << lo << ", hi: " << hi << endl;  ← commented-out debug
// lines are kept on purpose. They are how I debugged the code. Uncomment
// them when you read the function for the first time.

int x = 5;       // <-- inline narration in green is what I would say aloud

You will see this notation everywhere. It is not noise; it is the trace of how the code was written.

3.3 3. The colored boxes

Green — A short aside I would say in lecture. Usually fewer than three sentences. Often a war story or a piece of context that does not fit anywhere else.

Red — A common mistake that you will probably make at some point. The mistake is shown in code; the fix follows it.

Purple — Stop reading. Write code. Do not skip these. They are short and they are the only way the material sticks.

Blue (note) — Background information or a reference for further reading.

Yellow (tip) — A productivity trick or a tooling shortcut.

3.4 Setting up your environment

The code in this book targets g++ or clang++ with -std=c++17. To follow along you need:

  1. A C++ compiler (g++ on Linux, clang++ on macOS, MSVC or g++ via MinGW on Windows).
  2. An editor. I use Emacs. My students use VS Code, CLion, or Visual Studio. Any of them are fine. I do not care which editor you use as long as it has a debugger.
  3. valgrind (Linux) or AddressSanitizer (-fsanitize=address, all platforms). You will need this around chapter 4.
  4. A GitHub account.

See Appendix C: Toolchain for setup instructions per platform.

3.5 A typical compile command

g++ -Wall -Wextra -std=c++17 -fsanitize=address main.cpp -o main && ./main

That is the command. Put it in a shell alias. You will type it a thousand times this quarter.

3.6 Where the LeetCode problems live

Every chapter ends with three to five challenges. They are on leetcode.com/problemset. Free problems are sufficient — you do not need LeetCode premium to do anything in this book. Solutions in C++ (my submitted solutions, not always optimal but always honest) are linked from Appendix B: LeetCode Index.

3.7 When you get stuck

In order of escalation:

  1. Re-read the chapter.
  2. Look at the linked LeetCode submission.
  3. Ask in the course Discord. Students answer faster than I do.
  4. Ask me. I read every Discord message and every email. I do not always reply, but I read.
  5. If you found a bug in this book, open an issue. Or fix it and send a PR.

3.8 What you will not find here

  • A formal proof of every theorem. There are textbooks for that.
  • Every C++ language feature. There are 1,300 pages of Stroustrup for that.
  • Every leetcode problem worked out. There are 2,500 of them and I have only solved about 400.
  • Pretty pictures of trees. I draw them on the whiteboard. The book has ASCII trees and a few rendered diagrams. Get over it.

What you will find: the through-line. How recursion shows up in tree problems, which shows up in DP, which shows up in the proofs we did three weeks earlier, which mattered for the algorithm analysis we did six weeks earlier. The connections are the whole point.

Let us begin.