g↗genai/ learner
How Machines Learn / Lesson 07

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.

Concept + interactive labBeginner friendly

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.

On Rover’s 5×5 Warehouse aisle map

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.

Diagram titled Planning vs. Learning comparing two separate left-to-right tracks: Planning (Search) goes from Start, goal and map to Test moves ahead to Step-by-step plan; Learning (From data) goes from Past examples to Adjust settings to Spot patterns. Bottom cards show an Analogy of reading a road map versus spotting 5 p.m. traffic patterns and Key takeaways: Planning works on brand-new maps, Learning adapts from experience, Real AI often combines both.
Planning searches a map and rules for a route; learning adjusts internal settings from experience. Many real systems combine both.

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.

  1. 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.
  2. 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.
  3. 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.
  4. Click Reset map to restore the preset walls.
1. Choose a map
2. Choose a search order
Crate wallWaiting listCheckedPlanned route
0 squares checkedRoute: searching

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.

✎ Try it yourselfKnowledge check · Practice only

Check your understanding.

A warehouse robot receives the floor map of a brand-new building it has never visited before, with zero past delivery logs. Using the map and its allowed moves (up, down, left, right without hitting crates), it tests branches ahead of time and outputs a 9-step route from the loading dock to the packing table. Which statement best describes what the robot did?

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.