Alpha-Beta Pruning
Prerequisites
- Minimax Algorithm — Minimax value computation, backup process
- Game Theory Basics — Game trees, MAX/MIN players
🎯 Learning Objectives
- Understand why and how branches can be pruned without affecting the minimax value
- Track α and β values at every node during traversal
- Identify exactly which branches get pruned in a given game tree
- Derive best-case complexity O(bd/2) with perfect move ordering
- Solve GATE problems involving alpha-beta pruning
1. Intuition Behind Pruning
Minimax explores every node in the game tree — O(bm). But many branches are irrelevant because they can never influence the final decision. Alpha-beta pruning eliminates these branches while guaranteeing the same result as full minimax.
- α = the best (highest) value that MAX can guarantee along the current path. Initialized to −∞.
- β = the best (lowest) value that MIN can guarantee along the current path. Initialized to +∞.
Pruning rule: At any node, if α ≥ β, stop evaluating remaining children (prune).
If MAX already knows it can get a value of at least α, and MIN can force a value of at most β, and α ≥ β, then the current branch is irrelevant — MAX will never choose it (or MIN will never allow it).
2. Alpha-Beta Pseudocode
function ALPHA-BETA-SEARCH(state):
v ← MAX-VALUE(state, −∞, +∞)
return action in ACTIONS(state) with value v
function MAX-VALUE(state, α, β):
if IS-TERMINAL(state): return UTILITY(state)
v ← −∞
for each a in ACTIONS(state):
v ← max(v, MIN-VALUE(RESULT(state,a), α, β))
if v ≥ β: return v // β cutoff (prune)
α ← max(α, v)
return v
function MIN-VALUE(state, α, β):
if IS-TERMINAL(state): return UTILITY(state)
v ← +∞
for each a in ACTIONS(state):
v ← min(v, MAX-VALUE(RESULT(state,a), α, β))
if v ≤ α: return v // α cutoff (prune)
β ← min(β, v)
return v
β cutoff happens at MAX nodes: if MAX finds a child ≥ β, MIN (the parent) would never allow this path.
α cutoff happens at MIN nodes: if MIN finds a child ≤ α, MAX (the grandparent) already has a better option.
3. Complete Traced Example
Game tree (same as minimax example):
MAX (A)
/ \
MIN (B) MIN (C)
/ \ / \
MAX(D) MAX(E) MAX(F) MAX(G)
/ \ / \ / \ / \
3 5 6 9 1 8 2 7
Traversal (left-to-right DFS) with α-β:
Node A (MAX): α=−∞, β=+∞
→ Go to B
Node B (MIN): α=−∞, β=+∞
→ Go to D
Node D (MAX): α=−∞, β=+∞
Visit leaf 3: v=3, α=3
Visit leaf 5: v=5, α=5
Return 5
Back at B: v=min(+∞,5)=5, β=5
→ Go to E
Node E (MAX): α=−∞, β=5
Visit leaf 6: v=6, α=6
6 ≥ β(5) → β CUTOFF! Prune leaf 9.
Return 6
Back at B: v=min(5,6)=5
Return 5
Back at A: v=max(−∞,5)=5, α=5
→ Go to C
Node C (MIN): α=5, β=+∞
→ Go to F
Node F (MAX): α=5, β=+∞
Visit leaf 1: v=1, α=5
Visit leaf 8: v=8, α=8
Return 8
Back at C: v=min(+∞,8)=8, β=8
→ Go to G
Node G (MAX): α=5, β=8
Visit leaf 2: v=2, α=5
Visit leaf 7: v=7, α=7
Return 7
Back at C: v=min(8,7)=7
Return 7
Back at A: v=max(5,7)=7, α=7
Return 7
Result: Minimax value = 7
Pruned: leaf 9 (under node E)
Nodes saved: 1 leaf evaluation
Alpha-beta pruning’s effectiveness depends heavily on the order in which children are examined. In the worst case (reverse-sorted), no pruning occurs and it degenerates to full minimax.
4. Best-Case Complexity
With perfect move ordering (best moves examined first):
- Best-case Time: O(bd/2) — effectively doubles the searchable depth
- Worst-case Time: O(bd) — same as minimax (no pruning)
- Average case (random ordering): O(b3d/4)
- Space: O(bd) — same as minimax (DFS)
Best-case leaf nodes evaluated: 2bd/2 − 1 (for even d) or b⌊d/2⌋ + b⌈d/2⌉ − 1 (for odd d)
This means alpha-beta with perfect ordering can search a tree twice as deep as minimax in the same time. For chess (b≈35), this means searching to depth 12 instead of 6 in the same time.
5. Types of Cutoffs
| Cutoff Type | Occurs At | Condition | Meaning |
|---|---|---|---|
| α cutoff | MIN node | v ≤ α | MAX ancestor already has a better option |
| β cutoff | MAX node | v ≥ β | MIN ancestor won’t allow this path |
Some textbooks call these shallow cutoffs (immediate parent causes the prune) and deep cutoffs (a grandparent or higher ancestor causes the prune). Deep cutoffs are rarer but save more work.
6. GATE-Style Problems
MAX
/ | \
MIN MIN MIN
/\ /\ /\
3 5 2 9 1 6
Left-to-right α-β:
MIN-A: min(3,5)=3 → A=3
Back at MAX: α=3
MIN-B: first child=2. v=2 ≤ α(3) → α cutoff!
Leaf 9 is PRUNED.
Back at MAX: v still 3
MIN-C: first child=1. v=1 ≤ α(3) → α cutoff!
Leaf 6 is PRUNED.
Result: 3. Pruned nodes: 9, 6
Q: In a game tree of depth 4 and branching factor 3, how many leaf nodes does alpha-beta evaluate in the best case?
Solution: Best case: 2bd/2 − 1 = 2 × 32 − 1 = 2 × 9 − 1 = 17 leaf nodes (compared to 34 = 81 for full minimax).
MAX
/ \
MIN MIN
/ \ / \
8 3 1 7
Left-to-right:
MIN-L: min(8,3)=3. MAX: α=3
MIN-R: child 1 ≤ 3 → α cutoff. Prune 7.
Result: 3. Evaluated: 3 leaves.
Right-to-left:
MIN-R: min(7,1)=1. MAX: α=1
MIN-L: child 8 → v=8, then child 3 → v=3
Result: 3. Evaluated: 4 leaves (no pruning!)
Move ordering matters: left-to-right saved 1 evaluation.
Summary
- α tracks MAX’s best guaranteed value; β tracks MIN’s best guaranteed value.
- Prune when α ≥ β — the branch cannot affect the final result.
- Best-case complexity: O(bd/2) — doubles the searchable depth.
- Move ordering is critical; perfect ordering yields maximum pruning.
- Alpha-beta returns the exact same minimax value — it never changes the result.
References
- Russell, S. & Norvig, P. AIMA, 4th Ed. — Chapter 5.3
- Knuth, D. & Moore, R. “An Analysis of Alpha-Beta Pruning”, Artificial Intelligence, 6(4), 1975