Overview

3 Intelligent search

This chapter introduces intelligent search by showing how domain knowledge can steer exploration toward good solutions faster than uninformed strategies. It frames heuristics as problem-specific, educated guesses that score or constrain states when exact optimization is infeasible. Through everyday and practical examples—routing, preference scoring, and content matching—it illustrates how a well-chosen heuristic reshapes a search space. A weighted-maze scenario further grounds the idea: when some moves are costlier than others, the “best” path is determined by both the number of steps and their cumulative costs, so a heuristic that favors cheaper, shorter routes becomes a powerful guide.

The chapter then focuses on informed search methods, emphasizing A* as the workhorse. A* evaluates candidates by combining actual cost so far (g) with a heuristic estimate to the goal (h), exploring nodes via a priority queue that always selects the lowest estimated total cost (f = g + h). With an admissible (and, for graphs, consistent) heuristic, A* is guaranteed to find the optimal path while avoiding large swaths of unpromising nodes; with a poor heuristic, it forfeits that guarantee and efficiency. Practical details—tracking parents to reconstruct solutions, calculating costs on the fly, and choosing sensible heuristics like Manhattan distance—highlight how A* blends breadth- and depth-wise behavior in service of speed and optimality. Typical applications include game pathfinding, network routing, decoding in NLP, and puzzle solving.

Finally, the chapter turns to adversarial search, where outcomes depend on an opponent’s choices in zero-sum settings. Using Connect Four as a running example, it explains how min-max simulates alternating turns to a fixed depth, applies a heuristic to score leaf states (wins, losses, draws), and propagates values upward by alternating maximize/minimize decisions. Because the game tree grows explosively, the chapter introduces alpha-beta pruning, which maintains bounds (alpha for the maximizer, beta for the minimizer) to cut off branches that cannot change the final decision—yielding the same choice with far less computation. The section closes with use cases, from agents for perfect- and imperfect-information games to hybrid approaches that pair adversarial search with techniques like ant colony optimization for real-world routing.

Comparison of two audio clips using frequency distribution
Adjustments to the maze example: gravity
All possible movement options represented as a tree
The function for the A* search algorithm
The sequence of tree processing using A* search (part 1)
The sequence of tree processing using A* search (part 2)
Flow for the A* search algorithm
The sequence of tree processing using A* search (part 1)
The sequence of tree processing using A* search (part 2)
Nodes visited in the entire tree after A* search
The game of Connect Four
The sequence of tree processing using min-max search
The explosion of possibilities while searching the game tree
Scoring for the agent versus scoring for the opponent
Flow for the min-max search algorithm
A representation of the possible states in a Connect Four game
The possible end states in a Connect Four game
The possible scores for end states in a Connect Four game (part 1)
The possible scores for end states in a Connect Four game (part 2)
The possible scores for end states in a Connect Four game (part 3)
Simplified game tree with min-max scoring
An example of alpha-beta pruning
Flow for the min-max search algorithm with alpha-beta pruning

Summary of Intelligent search

FAQ

What is a heuristic in search, and why is it useful?A heuristic is a problem-specific rule of thumb that scores states or actions to estimate how promising they are. It injects domain knowledge to guide exploration, helping the algorithm focus on likely-good paths instead of exhaustively checking everything.
How does informed (heuristic) search differ from uninformed search?Uninformed methods like BFS or DFS explore systematically with no problem knowledge. Informed search uses a heuristic to prioritize which nodes to visit next, typically exploring far fewer nodes and reaching solutions faster.
What is A* search and how does its cost function work?A* ranks nodes by f(n) = g(n) + h(n), where g(n) is the actual cost from the start and h(n) is a heuristic estimate to the goal. A priority queue always expands the node with the lowest f, balancing progress made with estimated effort remaining.
When does A* guarantee the optimal path?A* is optimal if the heuristic is admissible (never overestimates the true remaining cost). On graphs with cycles, consistency (triangle inequality for h) is also required to maintain optimality and efficiency.
What makes a “good” heuristic?Good heuristics are informative (correlate with true cost), cheap to compute, problem-specific, and admissible/consistent when optimality is required. Examples include Manhattan distance on grids and cost models that reflect varied step costs.
How does A* use data structures like priority queues and visited sets?A* keeps an open set in a priority queue (often a min-heap) ordered by f(n). It pops the most promising node, generates neighbors, updates their costs and parents, and tracks a visited/closed set to avoid reprocessing worse alternatives.
How do action costs affect A* (e.g., the maze with “gravity”)?If moves have different costs, incorporate them into g(n). For example, if moving north/south is pricier than east/west, the cost function should add that penalty so A* prefers cheaper directions when they still reach the goal efficiently.
What are common use cases for informed search algorithms?- Pathfinding in games and robotics - Network routing and logistics - Decoding in NLP (e.g., beam search variants) - Solving puzzles and single-player games with clear state spaces
What is adversarial search, and how does min-max work?Adversarial search handles multi-agent, turn-based settings with opposing goals. Min-max simulates moves to a chosen depth, alternates maximizing the agent’s score and minimizing the opponent’s, and picks the root move that leads to the best worst-case outcome.
What is alpha-beta pruning and why is it valuable?Alpha-beta pruning tracks best-known bounds (alpha for the maximizer, beta for the minimizer). When a branch can’t improve the outcome, it is pruned. This yields the same min-max decision while exploring dramatically fewer nodes.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking AI Algorithms, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking AI Algorithms, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking AI Algorithms, Second Edition ebook for free