Worked Example: Minimax & Alpha-Beta

Complete Step-by-Step Solution for Classroom Teaching

Perfect for lectures, tutorials, and exam preparation

Complete Instructor Solution

This worked example provides a complete, detailed solution that instructors can use directly in lectures.

Students can follow along step-by-step to master minimax and alpha-beta pruning concepts.

Exercise Problem

The Starting Position

Consider the following Tic-Tac-Toe position where X = MAX and O = MIN:

1 X
2 O
3 X
4 O
5 X
6
7
8
9 O
Current State:
  • X (MAX) occupies: {1, 3, 5}
  • O (MIN) occupies: {2, 4, 9}
  • Empty positions: {6, 7, 8}
  • It's X's turn to play
Key Observations:
  • X has one immediate winning threat: Position 7 completes anti-diagonal {3,5,7}
  • Positions 6 and 8: Do not create immediate wins, game continues
  • Only one guaranteed winning path: X→7 is the optimal move
  • O cannot prevent the win if X plays optimally at position 7
Tasks to Complete
  • Part A: Build the complete game tree (6 points)
  • Part B: Apply Minimax evaluation (6 points)
  • Part C: Apply Alpha-Beta pruning (6 points)
  • Part D: Compare computational efficiency (2 points)
Part A Solution: Game Tree
1 Identify X's Legal Moves:
From the current position, X can play at any empty square:
  • Position 6: No immediate win, game continues
  • Position 7: Completes anti-diagonal (3-5-7) → X wins immediately
  • Position 8: No immediate win, game continues
2 Analyze Each Branch:
Branch 1: X plays at position 6
X
O
X
O
X
X
7
8
O
After X→6
O can respond at: {7, 8}
O→7:
Blocks anti-diagonal, then X→8 → 0 (Draw)
O→8:
X→7 completes anti-diagonal → +1 (X wins)
Branch 2: X plays at position 7
X
O
X
O
X
6
X
8
O
After X→7
X WINS!

Anti-diagonal: X-X-X (positions 3-5-7)
Utility: +1
Branch 3: X plays at position 8
X
O
X
O
X
6
7
X
O
After X→8
O can respond at: {6, 7}
O→6:
Then X→7 completes anti-diagonal → +1 (X wins)
O→7:
Blocks anti-diagonal, then X→6 → 0 (Draw)
🌳 Complete Game Tree
X's Turn (MAX Root - X wants to win) X [value: +1] / | \ (pos 6) (pos 7) (pos 8) / | \ / | \ / | \ / | \ O [0] +1 O [0] / \ ✅ WIN / \ O→7 / \ O→8 X→7 O→6 / \ O→7 / \ / \ / \ / \ 0 +1 +1 0 ⚪ Draw 🏆 WIN 🏆 WIN ⚪ Draw 📊 Step-by-Step Analysis: Branch 1 - X→6: • O can play at 7 → Draw (0) or at 8 → X wins (+1) • O chooses: MIN(0, +1) = 0 (defensive play at O→7) Branch 2 - X→7: • Immediate win! Completes anti-diagonal (3-5-7) • No O response needed → Direct win (+1) Branch 3 - X→8: • O can play at 6 → X wins (+1) or at 7 → Draw (0) • O chooses: MIN(+1, 0) = 0 (defensive play at O→7) 🎯 Final MAX Operation: MAX(0, +1, 0) = +1 ✅ Optimal move: X→7 (position 7) 🎖️ Guaranteed outcome: X wins!
Interactive Game Tree
flowchart TD Root["X (MAX)
Root Position
Value: +1"] O6["O (MIN)
After X→6
Value: 0"] Win7["🏆 X WINS
Move to pos 7
Anti-diagonal
Value: +1"] O8["O (MIN)
After X→8
Value: 0"] Draw6a["⚪ DRAW
O→7, X→8
Value: 0"] Win6b["🏆 X WINS
O→8, X→7
Value: +1"] Win8a["🏆 X WINS
O→6, X→7
Value: +1"] Draw8b["⚪ DRAW
O→7, X→6
Value: 0"] Root --> O6 Root --> Win7 Root --> O8 O6 --> Draw6a O6 --> Win6b O8 --> Win8a O8 --> Draw8b classDef maxNode fill:#28a745,stroke:#333,stroke-width:3px,color:#fff classDef minNode fill:#dc3545,stroke:#333,stroke-width:3px,color:#fff classDef winNode fill:#ffd700,stroke:#333,stroke-width:3px,color:#333 classDef drawNode fill:#6c757d,stroke:#333,stroke-width:3px,color:#fff class Root maxNode class O6,O8 minNode class Win7,Win6b,Win8a winNode class Draw6a,Draw8b drawNode
Key Insight

X has one guaranteed winning move (position 7)! The anti-diagonal threat (3-5-7) cannot be blocked by O. However, if X plays at positions 6 or 8, O can force a draw by playing defensively at position 7.

Part B Solution: Minimax Algorithm
1 Evaluate Leaf Nodes (Terminal States):
Starting from the bottom of the tree, assign utility values:
  • X→6, O→7, X→8: Draw → Utility = 0
  • X→6, O→8, X→7: X wins → Utility = +1
  • X→7: Immediate win (anti-diagonal) → Utility = +1
  • X→8, O→6, X→7: X wins → Utility = +1
  • X→8, O→7, X→6: Draw → Utility = 0
2 Propagate Values Up Through MIN Nodes:
For X→6 branch: O (MIN) chooses between:
  • O→7: Leads to utility 0 (Draw)
  • O→8: Leads to utility +1 (X wins)
MIN operation: MIN(0, +1) = 0
O chooses the defensive move O→7

For X→8 branch: O (MIN) chooses between:
  • O→6: Leads to utility +1 (X wins)
  • O→7: Leads to utility 0 (Draw)
MIN operation: MIN(+1, 0) = 0
O chooses the defensive move O→7
3 Propagate to Root (MAX Node):
X (MAX) at root chooses between:
  • Move to 6: Value = 0
  • Move to 7: Value = +1
  • Move to 8: Value = 0
MAX operation: MAX(0, +1, 0) = +1
Node Type Position/Move Available Options Operation Result
Leaf X→6, O→7, X→8 - Terminal (Draw) 0
Leaf X→6, O→8, X→7 - Terminal (X wins) +1
Leaf X→7 - Terminal (X wins) +1
Leaf X→8, O→6, X→7 - Terminal (X wins) +1
Leaf X→8, O→7, X→6 - Terminal (Draw) 0
MIN After X→6 [0, +1] MIN(0, +1) 0
MIN After X→8 [+1, 0] MIN(+1, 0) 0
MAX Root [0, +1, 0] MAX(0, +1, 0) +1
Minimax Decision

Optimal move for X: Position 7 is the only guaranteed winning move!

Guaranteed outcome: If X plays optimally (X→7), X wins (+1). If X plays suboptimally (X→6 or X→8), O can force a draw (0) with optimal defense.

Part C Solution: Alpha-Beta Pruning
1 Initialize Alpha-Beta Values:
Start at root with initial bounds:
α = -∞ (best value MAX can guarantee so far)
β = +∞ (best value MIN can guarantee so far)
2 Explore Left-to-Right: X→6 Branch
X plays at position 6: O responds optimally
O can choose O→7 (leads to draw, value=0) or O→8 (leads to X win, value=+1)
MIN chooses: MIN(0, +1) = 0
Update α: α = MAX(-∞, 0) = 0
Current bounds: α = 0, β = +∞
3 Continue with X→7 Branch
X plays at position 7: Immediate win! (anti-diagonal)
Leaf value = +1
Update α: α = MAX(0, +1) = +1
Current bounds: α = +1, β = +∞
4 Analyze X→8 Branch with Pruning Potential
Enter MIN node after X→8:
Current bounds: α = +1, β = +∞

O's first option (O→6):
  • Leads to X→7 winning with +1
  • Update β: β = MIN(+∞, +1) = +1
  • Check pruning condition: β = +1 ≤ α = +1 ✓
🚫 PRUNING OCCURS: Since β ≤ α, we can prune O's second option (O→7) because the MIN node already has a value (1) that equals the current alpha bound, meaning this branch won't improve the MAX node's result.

Note: Even though O→7 would lead to a draw (0), we don't need to evaluate it because MIN already found a path that equals the current alpha bound.

5 Final Alpha-Beta Result
Back at root: MAX chooses among [0, +1, 0] = +1
Result is identical to standard minimax!
X→8 branch evaluates to 0 in both algorithms - α-β just stops early once it determines the MIN node can't do better than 0
✂️ Alpha-Beta Pruning Tree
✂️ Alpha-Beta Search (α = -∞, β = +∞) X [α=-∞→0→+1, β=+∞] → +1 / | \ (pos 6) (pos 7) (pos 8) / | \ / | \ / | \ O [0] +1 O [0] / \ ✅ Immediate / \ O→7 / \ O→8 WIN O→6 / \ O→7 / \ (anti-diag) / \ / \ / \ 0 +1 +1 ✂️ ⚪Draw 🏆WIN 🏆WIN PRUNED ✅Eval ✅Eval ✅Eval ✗Skip 📋 Step-by-Step Alpha-Beta Execution: Step 1 - Evaluate X→6 branch: • O chooses MIN(0,+1) = 0 → Update α = 0 Step 2 - Evaluate X→7 branch: • Immediate win (+1) → Update α = +1 Step 3 - Start X→8 branch: • Evaluate O→6: leads to +1 → Update β = +1 Step 4 - Pruning occurs: • Check: β(+1) ≤ α(+1) ✓ → Prune O→7 branch! 🎯 Alpha-Beta Result: Same optimal move (X→7)! ⚡ Efficiency gain: 1/5 leaf evaluations saved (20%)
Alpha-Beta Pruning Visualization
flowchart TD Root["X (MAX)
α=-∞→+1, β=+∞
Value: +1"] Draw6["⚪ DRAW
Move to pos 6
Value: 0
✅ Evaluated"] Win7["🏆 X WINS
Move to pos 7
α=+1
✅ Evaluated"] O8["O (MIN)
After X→8
α=+1, β=+∞→+1
Value: 0"] WinO6["🏆 X WINS
O→6, then X→7
β=+1
✅ Evaluated"] PrunedO7["❌ PRUNED
O→7 branch
✂️ Skipped
β≤α cutoff"] Root --> Draw6 Root --> Win7 Root --> O8 O8 --> WinO6 O8 -.-> PrunedO7 classDef maxNode fill:#28a745,stroke:#333,stroke-width:3px,color:#fff classDef minNode fill:#dc3545,stroke:#333,stroke-width:3px,color:#fff classDef winNode fill:#ffd700,stroke:#333,stroke-width:3px,color:#333 classDef drawNode fill:#6c757d,stroke:#333,stroke-width:3px,color:#fff classDef prunedNode fill:#ffc107,stroke:#333,stroke-width:3px,color:#333 class Root maxNode class O8 minNode class Win7,WinO6 winNode class Draw6 drawNode class PrunedO7 prunedNode
Step Node α β Action Pruned?
1 Root -∞ +∞ Initialize No
2 X→6 branch 0 +∞ MIN(0,+1) = 0 No
3 X→7 +1 +∞ Immediate win: +1 No
4 After X→8 +1 +∞ Enter MIN node No
5 O→6 then X→7 +1 +1 Evaluate: +1, update β No
6 O→7 branch +1 +1 β ≤ α cutoff Yes
Alpha-Beta Efficiency

Nodes evaluated: 4 out of 5 leaf nodes (20% saving)

Same result: X's optimal move value = +1

Pruning benefit: We avoided evaluating the O→7 branch because we knew it couldn't change the MIN node's decision.

Part D Solution: Efficiency Comparison
Standard Minimax
  • Nodes evaluated: 5 leaf nodes
  • Tree traversal: Complete exploration
  • Result: X wins (+1)
  • Optimal move: X→7 only (guaranteed win)
  • Guarantees: Always finds optimal solution
Alpha-Beta Pruning
  • Nodes evaluated: 4 leaf nodes
  • Tree traversal: Strategic pruning
  • Result: X wins (+1) - identical!
  • Optimal move: X→7 only (guaranteed win) - same!
  • Guarantees: Same optimality, less work
1 Why Pruning Doesn't Change Results:

Alpha-beta pruning uses mathematical bounds to eliminate branches that provably cannot influence the final decision. When β ≤ α at a MIN node, we know that the parent MAX node will never choose this path because it already has a better alternative.

2 Computational Efficiency Gained:

In this example, pruning saved 20% of evaluations. In larger game trees, alpha-beta can achieve dramatic speedups - often reducing O(b^d) to O(b^(d/2)) in the best case, where b is branching factor and d is depth.

Key Insights for Students
🎯 Strategic Understanding:
  • Multiple threats create winning positions
  • Optimal play assumes intelligent opponents
  • Some positions have forced wins regardless of moves
⚡ Algorithmic Efficiency:
  • Smart pruning preserves optimality
  • Bounds-based reasoning saves computation
  • Order of exploration affects pruning effectiveness

Instructor Notes

Teaching Points to Emphasize
📚 Conceptual Learning:
  • Difference between immediate wins and complex analysis
  • How multiple threats create overwhelming advantages
  • Why optimal play assumes perfect opponent responses
  • Connection between game theory and algorithm design
🔧 Technical Skills:
  • Systematic tree construction and labeling
  • Bottom-up value propagation mechanics
  • Alpha-beta bound maintenance and update rules
  • Pruning condition recognition and application
Extensions for Advanced Students
  • Move Ordering: How would different exploration orders affect pruning efficiency?
  • Evaluation Functions: What if this weren't a terminal position but needed heuristic evaluation?
  • Iterative Deepening: How would time constraints change the search strategy?
  • Transposition Tables: Could we cache results for repeated board positions?

Explore More Exercises