Search and planning
Not every smart AI decision comes from training on past examples. Sometimes a system uses a map and a set of rules to test moves ahead and build a step-by-step plan.
How search builds a plan.
In this lesson, you will see how search builds a plan, compare three search orders, tell planning apart from learning, explore a live maze, and see where pure search hits a wall.
Start with five plain terms grounded in a simple floor grid:
- State: a possible situation—such as any square a robot could stand on in a warehouse.
- Move: one allowed step from a state to a neighboring state (up, down, left, or right without hitting a wall).
- Goal: the target state the system wants to reach.
- Branch: one sequence of moves splitting off at a fork in the map.
- Search and plan: search tests branches on the map to find a valid route, and the plan is the ordered list of moves from start to goal.
Rover (an invented toy robot for this lesson) needs to move from a Start square to a Goal square on a 5×5 warehouse floor without bumping into stacked crate walls.
Think of tracing a paper maze with your finger before walking through it. Your finger tests branches on the page, stops at dead ends, and only commits to a route once it sees a clear path to the exit.

How search chooses the next square.
When the search checks a fork on the map, it has to decide which open square to check next. Different search orders inspect different squares and can even return different routes.
1. Layer-by-layer (BFS)
Breadth-first search checks squares in order of fewest steps from Start—starting at Start (0 steps), then all squares 1 step away, then 2 steps away, and so on until it selects Goal.
Trade-off: Guaranteed to find a fewest-step route when every step costs the same, though it often checks many squares.
Everyday example: Looking for a quiet study room by checking rooms one doorway away first, then two doorways away.
2. Corridor-first (DFS)
Depth-first search follows its current branch until no unchecked legal moves remain, then backtracks to the most recent fork with an untried option.
Trade-off: Can reach the goal quickly on a lucky branch, or wander into a much longer detour.
Everyday example: Walking straight down one library wing until a dead end, then turning back to the last hallway fork.
3. Goal-guided (Heuristic)
Greedy goal-guided search uses a heuristic—a rough distance estimate (here, grid steps to Goal ignoring walls)—to pick the closest-looking square from all discovered-but-unchecked squares on its waiting list.
Trade-off: Often checks fewer squares, but walls can mislead the estimate into a longer detour than layer-by-layer search.
Everyday example: Walking toward the exit sign you can see across a hall, even if a closed door forces a detour.
Using our toy rules (Right, Down, Left, Up neighbor order; counting Start and Goal when selected; earliest-discovered tie-break for Goal-guided): Layer-by-layer checks 14 squares for a 5-step route, Corridor-first checks 12 squares for an 11-step detour, and Goal-guided checks 8 squares for the 5-step route.
Why planning is not learning.
A common misconception is that because a search program tests moves and backtracks away from dead ends, it must be learning. To tell them apart, ask one question: where does the answer come from?
Planning (Search)
Starts from an explicit start state, goal, and map of allowed moves. It tests future sequences of moves to produce a plan.
Key clue: Works on a brand-new warehouse map with zero past examples. Keeping track of visited squares is search bookkeeping for this run, not learning.
Everyday example: A GPS app searching a road map for turns from your home to a new clinic.
Learning (From data)
Uses data or past experience to adjust a model’s internal settings (the numbers that shape its predictions) so it handles future cases better.
Key clue: Spots patterns across examples instead of stepping through a rulebook of moves one by one.
Everyday example: An email filter adjusting its settings from labeled messages to recognize spam patterns.

In practice, real AI systems often combine both ideas. A navigation app can use a learned model to predict 5 p.m. traffic slowdowns, then run search on those updated travel times to plan your route; game systems like AlphaGo pair a learned model that scores how strong a board position looks with search that tests future moves ahead.
Maze route explorer.
Watch Rover test squares on a simplified 5×5 warehouse grid. Notice how changing the crate walls lets Rover replan right away without any training examples.
- On Warehouse aisle, click Run to goal with Layer-by-layer (BFS), then switch to Corridor-first (DFS) and Goal-guided (Heuristic) to compare squares checked and route length.
- Switch to Detour trap and compare Layer-by-layer (BFS) (6 steps) with Goal-guided (Heuristic) (8 steps) to see why a distance estimate can still take a longer detour.
- Still on Detour trap with Goal-guided (Heuristic), click Row 4, Col 1 to place a crate wall, then click Run to goal to watch Rover replan immediately—the route shortens from 8 steps to 6.
- Click Reset map to restore the preset walls.
Ready on Warehouse aisle. Click Step forward or Run to goal—or click any open square or crate to edit the map and replan with zero training examples.
Checks squares in order of fewest steps from Start. Guaranteed to find a shortest-step route when every step costs the same.
Two horizontal crate shelves create a short left corridor and a long outer loop.
Simplified toy rules: Equal cost per step, no diagonal moves, neighbors checked in Right, Down, Left, Up order. “Checked” counts each square once when selected (including Start and Goal). In Goal-guided mode, the small number in each square is its estimated steps to Goal ignoring walls, and ties pick the earliest-discovered square.
Where search hits a wall.
Search and planning are reliable when rules and maps are clear, but pure search has real limits:
- Branching explosion: When every step opens dozens of choices (as in complex board games or open-ended language), the number of branches grows faster than time and memory allow.
- Stale or missing maps: If someone moves a crate in the real warehouse and the map is not updated, Rover’s plan can run straight into a surprise obstacle.
- No automatic improvement across runs: In this maze, search starts fresh on each run. Even when a real planner caches a past route to save time, search by itself does not adjust internal model settings from data unless paired with a learning component.
- When search backtracks out of a dead end, is it learning from its mistake?
No. Marking a square as visited is temporary bookkeeping for the current search so Rover does not walk in circles. It does not change how Rover will handle future warehouses.
- Does goal-guided search always find the shortest route?
No. Because a simple distance estimate ignores walls, greedy goal-guided search can take a longer detour, as you saw on the Detour trap map. On an equal-cost, four-direction grid like this maze, more advanced planners (such as A* search) combine steps taken so far with the grid-step distance estimate to find a shortest route.
- Can one AI system use both planning and learning?
Yes. Combining learned estimates with step-by-step search lets systems handle huge spaces that neither method solves well alone.
Check your understanding.
Take this with you.
Planning searches rules; learning adapts from data. Search tests allowed moves on a map to build a step-by-step plan toward a goal—even on a brand-new map with zero past examples. Real AI systems often combine both, using learned estimates to guide smarter search.
Ready to continue? Return to How Machines Learn.