1The Puzzle
2The Briefing
3The Search
4Case Notes
5The Method
6New Cases
Chapter 1 · The Puzzle

🕵️ Exploring the Unknown

Imagine you need to find something in a large environment where you cannot see everything at once. From your current position, there may be several different paths leading to new and unexplored places.

As you move forward, each new place may reveal more possibilities. Without a clear approach, it can become difficult to keep track of where you have already been and which path you should explore next.

Let's play a game where you'll explore a set of connected directories to find a missing file. Follow each path carefully and keep track of the folders you have already explored.

Let's see what this looks like through a story 👇

Chapter 2 · A Search Adventure

The Missing Homework

🎉

Yay, hurray, you found the homework!

0
Score
0
Folders Opened
Chapter 4 · Case Notes

What did you notice?

Sit with these for a moment, there's no single correct wording, just think them through in your own words.

1 · Exploring the DirectoriesWhat strategies did you use to explore the directories?
2 · Handling a Dead EndWhat told you it was time to stop going forward and return to the previous folder?
3 · Choosing What to Do NextAfter reaching a dead end, would you prefer to go back to the previous folder and try another option, or restart the search from the beginning? Why?
4 · Tracking What You Already CheckedHow did knowing which folders you had already opened help you avoid repeating the same search? What would you do if the folder numbers became very large and you had to keep track of many visited folders?
5 · Reconstructing the StrategyImagine someone else must find the file using the strategy you used in the game. What step-by-step instructions would you give them?
Chapter 5 · The Method

How the search really worked

Here's the strategy you were using the whole time, with a name and a shape.

🌳

You Discovered: Depth-First Search (DFS)!

💻 📁 📁 📁 📄 📁 📁

That's exactly the habit you built by hand while hunting for Homework.pdf:

  • Step into a folder, then immediately step into the next one inside it, as deep as you can go.
  • Hit a dead end (an empty folder)? Back out exactly one step.
  • From there, try the next unopened folder, going deep again before drifting sideways.
  • Repeat until you find what you're looking for, or there's nowhere left to check.

That strategy has a name: Depth-First Search. It always commits to one path fully before backtracking to try another.

📚 Why a Stack?

DFS remembers where to go next using a stack, a pile where you can only add or remove from the top. Every time you open a folder, it gets placed on top of the stack. When you hit a dead end, you pop the top folder off and land back on the one below it, exactly the folder you'd expect to return to.

Try it yourself: each push opens the next folder on the real path to Homework.pdf, then pop it to back out, exactly like the search you just ran.

🔑 Key Learnings

🧭
The Strategy

Go as deep as possible down one path before trying another, commit fully, and only backtrack once you truly hit a dead end.

📚
The Stack

The last folder you opened is the first one you return to. That "last in, first out" order is exactly what a stack gives you.

✅
Why It Works

Backing out exactly one step (instead of starting over) means you never skip a folder and never waste time re-checking one.

🌍
Where You'll See It

File explorers, maze-solving, puzzle games, web crawlers, and countless programming problems all lean on this exact idea.

Chapter 6 · New Cases

Put the idea to the test

New situations to think through using what you just discovered.

1 · Compare EfficiencyTwo algorithms explore the same graph. One follows a path deeply before backtracking, while the other explores all nearby vertices first. What factors would you examine to decide which approach is more suitable for the problem?
2 · Recognize the PatternA problem requires exploring every possible path from a starting point, including paths that may lead several steps deeper before another option is considered. What features would make a depth-first approach suitable?
3 · Spot the MisconceptionSomeone says, "DFS is better for finding the nearest target because it reaches a target as quickly as possible by going deep." What is wrong with this reasoning?
4 · Change the ConstraintsA DFS is exploring a very large graph, but the search can only keep a limited number of locations in memory. How might this constraint affect your choice of search strategy?
5 · Unfamiliar ApplicationA software project contains many files, and some files depend on others. You want to explore all dependencies starting from one file, following each dependency as deeply as possible before returning to another dependency. How could this approach help, and what could cause the search to revisit the same file?
6 · Maze to Graph
Start Exit
Look at the maze provided above. If you wanted to represent this maze as a graph, what would the rooms or positions represent, and what would the connections between them represent? Once represented as a graph, how could you explore it by following one path as deeply as possible before going back and trying another path?

⏸ Paused

Take a breath. The clock is frozen, the folders aren't going anywhere.

🏆 Achievement unlocked