Alpha-Beta Pruning: A Complete Solved Numerical Example

Scenario: Turn-Based Board Game AI

The Objective: You are programming an AI (MAX) to find the move that yields the highest score, while anticipating an opponent (MIN) who will always choose the path that hurts you the most. Use Alpha-Beta Pruning to find the optimal path while instantly cutting off branches that are mathematically irrelevant.

Core Mechanics
  • MAX only updates α\alpha: It starts at -\infty because MAX is searching for the highest possible value. α\alpha represents the best score MAX is guaranteed so far.
  • MIN only updates β\beta: It starts at ++\infty because MIN is searching for the lowest possible value. β\beta represents the best score MIN is guaranteed so far.
  • Down vs. Up: The boundary limits (α\alpha and β\beta) flow down the tree. The evaluated leaf scores flow up the tree.
  • The Cutoff: If αβ\alpha \ge \beta at any node, the algorithm instantly stops evaluating that branch. The opponent would never allow this path to be reached!

Step 1: The Initial Game Tree

Before we begin evaluating, here is the full structure of the game tree. The algorithm tracks α\alpha (Alpha) for the MAX player and β\beta (Beta) for the MIN player.

Step 2: Step-by-Step Resolution

Watch the full global tree update as the depth-first search traverses back up. The active node being evaluated is highlighted with a glowing blue ring.

1

Evaluating Node: C

Position:Level 2 (Bottom-most evaluating layer)Layer Type:MAX

Received α\alpha: -∞Received β\beta: ∞
Child Node Evaluations
Evaluated child 8 (returns 8)
Update: α\alpha = 8, β\beta = ∞max(,8)=8max(-∞, 8) = 8
Evaluated child 3 (returns 3)
Update: α\alpha = 8, β\beta = ∞max(8,3)=8max(8, 3) = 8
Result: Node C locks in a value of 8.
Global Tree State (Step 1)
α:-∞
β:
Root
α:-∞
β:
A
B
α:-∞8
β:
C [8]
D
E
F
G
8
3
9
-2
5
7
2
4
6
8
1
2

Evaluating Node: D

Position:Level 2 (Bottom-most evaluating layer)Layer Type:MAX

Received α\alpha: -∞Received β\beta: 8
Child Node Evaluations
Evaluated child 9 (returns 9)
Update: α\alpha = 9, β\beta = 8max(,9)=9max(-∞, 9) = 9
✂️Pruning triggered! α\alpha (9) >= β\beta (8)
Result: Node D locks in a value of 9.
Global Tree State (Step 2)
α:-∞
β:
Root
α:-∞
β:8
A
B
C [8]
α:-∞9
β:8
D [9]
E
F
G
8
3
9
-2 [PRUNED]
5
7
2
4
6
8
1
3

Evaluating Node: E

Position:Level 2 (Bottom-most evaluating layer)Layer Type:MAX

Received α\alpha: -∞Received β\beta: 8
Child Node Evaluations
Evaluated child 5 (returns 5)
Update: α\alpha = 5, β\beta = 8max(,5)=5max(-∞, 5) = 5
Evaluated child 7 (returns 7)
Update: α\alpha = 7, β\beta = 8max(5,7)=7max(5, 7) = 7
Result: Node E locks in a value of 7.
Global Tree State (Step 3)
α:-∞
β:
Root
α:-∞
β:8
A
B
C [8]
D [9]
α:-∞57
β:8
E [7]
F
G
8
3
9
-2 [PRUNED]
5
7
2
4
6
8
1
4

Evaluating Node: A

Position:Level 1 (Intermediate Layer)Layer Type:MIN

Received α\alpha: -∞Received β\beta: ∞
Child Node Evaluations
Evaluated child C (returns 8)
Update: α\alpha = -∞, β\beta = 8min(,8)=8min(∞, 8) = 8
Evaluated child D (returns 9)
Update: α\alpha = -∞, β\beta = 8min(8,9)=8min(8, 9) = 8
Evaluated child E (returns 7)
Update: α\alpha = -∞, β\beta = 7min(8,7)=7min(8, 7) = 7
Result: Node A locks in a value of 7.
Global Tree State (Step 4)
α:-∞
β:
Root
α:-∞
β:87
A [7]
B
C [8]
D [9]
E [7]
F
G
8
3
9
-2 [PRUNED]
5
7
2
4
6
8
1
5

Evaluating Node: F

Position:Level 2 (Bottom-most evaluating layer)Layer Type:MAX

Received α\alpha: 7Received β\beta: ∞
Child Node Evaluations
Evaluated child 2 (returns 2)
Update: α\alpha = 7, β\beta = ∞max(,2)=2max(-∞, 2) = 2
Evaluated child 4 (returns 4)
Update: α\alpha = 7, β\beta = ∞max(2,4)=4max(2, 4) = 4
Evaluated child 6 (returns 6)
Update: α\alpha = 7, β\beta = ∞max(4,6)=6max(4, 6) = 6
Result: Node F locks in a value of 6.
Global Tree State (Step 5)
α:-∞7
β:
Root
A [7]
α:7
β:
B
C [8]
D [9]
E [7]
α:7
β:
F [6]
G
8
3
9
-2 [PRUNED]
5
7
2
4
6
8
1
6

Evaluating Node: B

Position:Level 1 (Intermediate Layer)Layer Type:MIN

Received α\alpha: 7Received β\beta: ∞
Child Node Evaluations
Evaluated child F (returns 6)
Update: α\alpha = 7, β\beta = 6min(,6)=6min(∞, 6) = 6
✂️Pruning triggered! α\alpha (7) >= β\beta (6)
Result: Node B locks in a value of 6.
Global Tree State (Step 6)
α:-∞7
β:
Root
A [7]
α:7
β:6
B [6]
C [8]
D [9]
E [7]
F [6]
G [PRUNED]
8
3
9
-2 [PRUNED]
5
7
2
4
6
8 [PRUNED]
1 [PRUNED]
7

Evaluating Node: Root

Position:Level 0 (Root Node)Layer Type:MAX

Received α\alpha: -∞Received β\beta: ∞
Child Node Evaluations
Evaluated child A (returns 7)
Update: α\alpha = 7, β\beta = ∞max(,7)=7max(-∞, 7) = 7
Evaluated child B (returns 6)
Update: α\alpha = 7, β\beta = ∞max(7,6)=7max(7, 6) = 7
Result: Node Root locks in a value of 7.
Global Tree State (Step 7)
α:-∞7
β:
Root [7]
A [7]
B [6]
C [8]
D [9]
E [7]
F [6]
G [PRUNED]
8
3
9
-2 [PRUNED]
5
7
2
4
6
8 [PRUNED]
1 [PRUNED]

Final Takeaway

Notice the two types of pruning! At Node D (Beta Cutoff): MIN already secured an 8 at Node C. When D reveals a 9, MIN immediately rejects it, saving us from checking D's remaining leaves. At Node B (Alpha Cutoff): Node F caps B's potential at 6. Since MAX already secured a guaranteed 7 on the left side, it completely abandons the entire right branch (G)!