AI as Search: The Foundation of Intelligent Problem-Solving
Understanding How GPS Navigation, Game-Playing Computers, and AI Systems Actually Work
Why Search is Everywhere in AI
From GPS routing to chess engines and Go AI, search algorithms underpin the core mechanisms of modern artificial intelligence.
"AI as search"is a foundational principle in computerized problem solving.
The following sections explain these concepts using only high school level mathematics.
The Foundation - State Space Search
What is State Space Search?
Think of any problem as a journey through different "states" - snapshots of the world at different points in time. Getting from your house to the grocery store? Each intersection is a state. Solving a puzzle? Each configuration of the puzzle is a state.
The key components are:
- States: All possible situations we might encounter
- Initial State: Where we start
- Goal Condition: What we're trying to achieve
- Actions: How we move from one state to another
Example: The 15-Puzzle
Consider this classic sliding puzzle where you need to arrange numbers 1-15 in order:
Goal State vs Current State
Goal State: Current State: ┌─────────────────┐ ┌─────────────────┐ │ 1 2 3 4 │ │ 4 1 2 3 │ │ 5 6 7 8 │ │ 5 6 7 11 │ │ 9 10 11 12 │ │ 8 9 10 │ │13 14 15 │ │12 13 14 15 │ └─────────────────┘ └─────────────────┘
Each arrangement of tiles is a state. Moving a tile into the empty space is an action. Our goal is to find a sequence of actions that transforms the current state into the goal state.
Basic Search Strategies
Depth-First Search (DFS): Going Deep
Imagine you're exploring a maze. Depth-First Search is like always taking the first path you see and following it as far as possible before backtracking.
How DFS Works:
1. Start at initial state 2. Pick a successor and go there 3. Keep picking successors and going deeper 4. If you hit a dead end, backtrack to the most recent choice point 5. Try the next unexplored option
The Algorithm (in simple terms):
Create a stack (like a stack of cafeteria trays) Put the starting state on top While the stack isn't empty: Take the top state off the stack If it's the goal, we're done! Otherwise, generate all its successors Put the new successors on top of the stack
DFS in Action - Simple Example:
1 / \ 2 3 / / \ 4 5 6
DFS would explore: 1 → 2 → 4 (dead end, backtrack) → 3 → 5 (dead end, backtrack) → 6
Breadth-First Search (BFS): Going Wide
BFS is like exploring all rooms on the current floor before going upstairs.
How BFS Works:
1. Start at initial state 2. Explore ALL immediate successors first 3. Then explore all successors of those successors 4. Continue layer by layer
The Algorithm:
Create a queue (like a line at the bank) Put the starting state at the back of the line While the queue isn't empty: Take the front state from the line If it's the goal, we're done! Otherwise, generate all its successors Put the new successors at the back of the line
BFS on the same example:
BFS would explore: 1 → 2, 3 → 4, 5, 6
Which is Better?
BFS guarantees the optimal solution - it finds the goal that requires the fewest steps.
DFS is often more memory-efficient and can find solutions faster, but they might not be optimal.
The choice depends on your problem! For GPS navigation, you want the shortest route (BFS-style thinking). For exploring possibilities in a game, DFS might work fine.
Smart Search with Heuristics - A* Algorithm
The Problem with Blind Search
Both DFS and BFS are "blind" search strategies - they explore without any knowledge about where the goal might be. Akin to inspecting every room in a house when you have no idea where your keys are.
Enter Heuristics: Adding Intelligence
A heuristic function h(s) gives us an estimate of how far we are from the goal. It's our "educated guess" about which direction to go.
Examples of Good Heuristics:
- Route Finding: Straight-line distance between two cities
- 15-Puzzle: Number of tiles in the wrong position
- 15-Puzzle (Better): Sum of Manhattan distances (how many moves each tile needs)
The A* Algorithm: Best of Both Worlds
A* combines what we know (how far we've come) with what we estimate (how far we have to go):
A* Evaluation Function:
f(s) = g(s) + h(s) Where: - g(s) = sum of cost from initial state to reach state s - h(s) = estimated cost from s to nearest goal - f(s) = estimated total cost of solution through s
A* Algorithm:
Create a priority queue (like an emergency room - most urgent first) Add starting state with priority f(start) While queue isn't empty: Remove state with lowest f value If it's the goal, we're done! For each successor: Calculate f = g + h Add to queue with this priority
The Power of Admissible Heuristics
A heuristic is admissible if it never overestimates the actual cost. Think of it as being "optimistically realistic" - you might underestimate how far you have to go, but you'll never overestimate.
Mathematical definition:
For all states s: 0 ≤ h(s) ≤ h*(s)
Where h*(s) is the true shortest distance to the goal.
Why this matters: If h(s) is admissible, A* is guaranteed to find the optimal solution!
A* in GPS Navigation
When your GPS calculates a route:
- g(s) = distance you've already traveled
- h(s) = straight-line distance to destination (admissible!)
- f(s) = estimated total trip distance
The GPS explores routes with the lowest f values first, ensuring you get an optimal path.
Game Tree Search - When Your Opponent Fights Back
The Challenge of Adversarial Search
Playing games against opponents introduces a new complexity: your opponent is actively trying to defeat you! This isn't just finding a path to a goal - it's finding the best strategy when someone is working against you.
Minimax: The Foundation of Game AI
The core insight is simple:
- On your turn: Choose the move that maximizes your score
- On opponent's turn: They'll choose the move that minimizes your score
Minimax Algorithm:
If it's my turn (MAX): Pick the action with the highest value If it's opponent's turn (MIN): Opponent picks the action with the lowest value (for me)
Minimax in Action: Tic-Tac-Toe
My Turn (MAX) / | \ O's Turn O's Turn O's Turn (MIN) (MIN) (MIN) / | \ / | \ / | \ +1 0 -1 +1 -1 0 -1 +1 0 Where: +1 = I win, 0 = draw, -1 = I lose
The algorithm works backwards:
- Calculate values at terminal positions (+1, 0, -1)
- MIN nodes: opponent picks lowest value
- MAX nodes: I pick highest value
- Propagate values up the tree
The Minimax Algorithm in Detail:
MaxTurn(state): If cutoff(state): return evaluation(state) value = negative infinity For each possible action: child_value = MinTurn(result of action) if child_value > value: value = child_value best_action = action return value, best_action MinTurn(state): If cutoff(state): return evaluation(state) value = positive infinity For each possible action: child_value = MaxTurn(result of action) if child_value < value: value = child_value best_action = action return value, best_action
Alpha-Beta Pruning: Making Minimax Efficient
The brilliant insight: you don't need to explore every branch!
Key Idea: If you find a move that's worse than something you've already found, stop looking at that branch.
Example:
MAX / \ MIN MIN / | / | \ 5 4 ? ? ?
After finding the left MIN node evaluates to 4, if the right MIN node starts with a value ≥ 4, we can stop exploring that branch because MAX will never choose it.
Alpha-Beta Rules:
- Alpha (α): Best value MAX can guarantee so far
- Beta (β): Best value MIN can guarantee so far
- Prune when α ≥ β: No need to explore further
This can reduce the search tree dramatically while finding the exact same answer!
Real-World Impact: Deep Blue vs. Kasparov (1997)
Deep Blue's victory over world champion Garry Kasparov used minimax with alpha-beta pruning, plus many refinements:
- Sophisticated evaluation functions
- Move ordering to improve pruning
- Specialized hardware
- Opening books and endgame databases
Monte Carlo Tree Search - The Modern Revolution
The Problem with Traditional Game Tree Search
Traditional minimax works great for games like chess, but what about Go?
- Branching factor: Chess has ~35 moves per position; Go has ~250+
- Evaluation difficulty: It's hard to evaluate Go positions without playing to the end
- Tree size: The search space is astronomically large
Enter Monte Carlo Tree Search (MCTS)
MCTS uses a radically different approach: instead of trying to evaluate positions with clever functions, just play lots of games to the end and see what happens!
Core Philosophy:
- Simulate thousands of random games
- Track which moves lead to more wins
- Gradually focus search on promising moves
The Four Steps of MCTS
1. Selection: Navigate down the tree using a smart formula that balances:
- Exploitation: Go toward moves that have worked well
- Exploration: Try moves that haven't been tested much
UCT (Upper Confidence bound applied to Trees) Formula:
Choose move i that maximizes: [Wins_i / Plays_i] + c × √(ln(Total_Plays) / Plays_i) Where: - Wins_i / Plays_i = win rate for move i - Second term = exploration bonus (larger for less-tried moves) - c = exploration parameter (typically √2)
2. Expansion: When you reach a leaf node (a position with untried moves), add one new child node for an untried move.
3. Simulation: From this new position, play a complete random game to the end. This is called a "playout" or "rollout."
4. Backpropagation: Take the result (win/loss) and update statistics for every node on the path back to the root.
MCTS Algorithm:
While time remaining: # Selection: Navigate to leaf using UCT leaf = select_best_path_to_leaf(root) # Expansion: Add one new child child = add_new_child(leaf) # Simulation: Play random game to end result = play_random_game(child) # Backpropagation: Update all nodes on path update_path_statistics(child, result) # Choose move that was simulated most often return most_simulated_move(root)
Why MCTS Works: The Multi-Armed Bandit Connection
MCTS treats move selection like a "multi-armed bandit" problem - imagine slot machines with different payout rates. You want to:
- Try each machine enough to estimate its payout
- Spend most time on the best machines
- Still occasionally try other machines in case you were wrong
The UCT formula solves this mathematically, with theoretical guarantees about minimizing regret!
MCTS Success Stories
AlphaGo (2016): Defeated Lee Sedol 4-1
- Combined MCTS with deep neural networks
- Neural networks guided both selection and evaluation
- Revolutionized computer Go
Beyond Go:
- Poker: Handle incomplete information through simulation
- Real-time strategy games: Manage complex state spaces
- General game playing: Works without game-specific knowledge
Benefits of MCTS:
- No evaluation function needed: Just simulate to the end
- Anytime algorithm: Can stop and make a decision whenever time runs out
- Handles large branching factors: Naturally focuses on promising moves
- Theoretically grounded: Mathematical guarantees about convergence
Connecting Theory to Practice
Why These Algorithms Matter
These aren't just academic exercises - they're the engines that power technologies you use every day:
GPS Navigation (A*):
- States: Road intersections
- Actions: Driving between intersections
- Heuristic: Straight-line distance
- Goal: Reach destination optimally
Game AI (Minimax + Alpha-Beta):
- Chess engines, checkers programs
- Perfect play in solved games
- Real-time strategy game AI
Modern AI Systems (MCTS + Deep Learning):
- AlphaGo, AlphaZero revolutionized game AI
- Planning in robotics
- Decision-making under uncertainty
The Evolution of AI Search
- 1950s: Basic minimax (Turing, Shannon)
- 1960s: Alpha-beta pruning (McCarthy)
- 1970s-90s: Sophisticated evaluation functions
- 1997: Deep Blue defeats Kasparov
- 2006: MCTS developed
- 2016: AlphaGo defeats Lee Sedol
- 2017: AlphaZero masters chess, Go, and shogi from scratch
Key Insights About AI
From these algorithms, we learn fundamental truths about artificial intelligence:
- Computers solve problems differently than humans: Methodical exploration vs. intuition
- Brute force + clever pruning is powerful: Sometimes trying many possibilities systematically beats trying to be clever
- Good heuristics are crucial: The right evaluation function can make the difference between feasible and impossible
- Simulation can replace evaluation: Sometimes it's easier to just try it than to predict what will happen
Mathematical Beauty in Simple Terms
Notice that all these algorithms use high school math:
- Counting: Tracking wins/losses, visits
- Averages: Win rates, expected values
- Comparisons: Max/min operations
- Logarithms: In the UCT formula (but just to balance exploration)
- Basic probability: Understanding that more trials give better estimates
No calculus, linear algebra, or advanced statistics required for the core ideas!
Building Intuition - Practice Problems
Problem 1: Heuristic Evaluation
For the 15-puzzle, which heuristic is better and why?
- h₁(s) = number of tiles in wrong position
- h₂(s) = sum of Manhattan distances
Answer: h₂ is better because it's more informed (gives better estimates) while still being admissible.
Problem 2: Alpha-Beta Pruning
Given this game tree, where can we prune?
MAX / \ MIN MIN / | / | \ 3 5 2 ? ?
Answer: After finding the right MIN node starts with 2, we can prune the remaining branches because MAX will choose the left side (5 > 2).
Problem 3: MCTS Decision
After 1000 simulations:
- Move A: 400 plays, 240 wins (60% win rate)
- Move B: 100 plays, 70 wins (70% win rate)
- Move C: 500 plays, 200 wins (40% win rate)
Which move should MCTS choose for the next simulation?
Answer: Likely Move B, because it has a high win rate but relatively few plays, so the exploration term in UCT will be large.
The Foundation of AI
Search algorithms represent one of the foundational ideas in artificial intelligence. From the systematic exploration of depth-first and breadth-first search, through the intelligent guidance of A*, to the adversarial reasoning of minimax and the simulation-based approach of MCTS, these algorithms demonstrate how computers can solve complex problems through methodical exploration.
The next time you use GPS navigation, play a computer game, or read about AI breakthroughs like AlphaGo, remember: you're witnessing the power of search algorithms that transform problems into systematic exploration of possibilities.
While serving as a teaching assistant for Professor Hirsh, he would say: "AI as search" isn't just one approach among many - it's a fundamental way of thinking about how intelligent systems can navigate the space of possible solutions to find the best answers. And the beautiful thing is, it all builds on mathematical concepts we already understand.
Intelligence doesn't always require intuition or inspiration. Sometimes it just requires being systematic, strategic, and thorough in exploring possibilities. And that's something computers can do well with compute.
"If I have seen further it is by standing on the shoulders of Giants." - Isaac Newton
The same is true for AI systems: each algorithm builds on previous insights, creating increasingly powerful systems that can tackle more complex problems. I hope these fundamentals have given you the foundation to understand how modern AI really works.