Artificial Intelligence: Alpha-Beta Pruning

Alpha-beta pruning is an optimization technique for the minimax algorithm, used in artificial intelligence for decision-making in two-player, zero-sum games like chess or tic-tac-toe. It reduces the number of nodes evaluated in the search tree by eliminating branches that cannot influence the final decision, thus improving efficiency without affecting the outcome.


Key Concepts

  • Minimax Algorithm: A recursive algorithm that evaluates all possible moves to find the best one. The maximizing player aims for the highest score, while the minimizing player aims for the lowest. It explores the game tree exhaustively, which can be computationally expensive.
  • Alpha: The best (highest) value a maximizing node can guarantee at the current level or above. Initially set to negative infinity.
  • Beta: The best (lowest) value a minimizing node can guarantee at the current level or above. Initially set to positive infinity.
  • Pruning: Skipping branches where further exploration won't improve the outcome based on current alpha and beta values.


How Alpha-Beta Pruning Works

  1. Traverse the Game Tree: Like minimax, alpha-beta pruning explores the tree depth-first, evaluating nodes from leaves to root.
  2. Track Alpha and Beta:
    • At maximizing nodes, update alpha if a higher value is found.
    • At minimizing nodes, update beta if a lower value is found.
  3. Prune Branches:
    • If a node's beta is less than or equal to its parent's alpha (β ≤ α), further exploration of that node's children is unnecessary, as the parent won't choose this branch (pruning occurs).
    • This happens because the minimizing node has found a value low enough that the maximizing parent won't select it, or vice versa.
  4. Pass Alpha and Beta: Propagate updated alpha and beta values to child nodes to guide pruning in deeper levels.

When to Prune

  • At a Min Node: If the node’s value becomes less than or equal to α, prune remaining children.

  • At a Max Node: If the node’s value becomes greater than or equal to β, prune remaining children.


Example

Let’s consider a simple game tree with a depth of 2 (Max → Min → Leaf):

            MAX
          /     \
       MIN       MIN
      / | \     / | \
     3  5  6   1  2  9

Let’s perform Alpha-Beta Pruning on this tree.


Step-by-step Alpha-Beta Pruning:

Initialize:

  • α = -∞

  • β = +∞

1. Root: MAX Node

Explore left MIN node.

2. Left MIN Node
  • α = -∞, β = +∞

Check child 3 → update β = 3

Check child 5
Since 5 > 3 → no update to β

Check child 6
Since 6 > 3 → no update

Return β = 3 to MAX node
⮕ MAX: α = max(-∞, 3) = 3

3. Right MIN Node
  • α = 3 (carried from MAX node)

  • β = +∞

Check child 1
→ β = min(+∞, 1) = 1

Now β (=1) < α (=3)

Prune remaining children (2, 9)
of this MIN node.

Return 1 to MAX

4. MAX Node

Now has values:
Left MIN → 3
Right MIN → 1

Final result: MAX chooses 3 as optimal move.


Final Tree Traversed:

Only visited leaf nodes: 3, 5, 6, 1
Pruned: 2, 9


Advantages of Alpha-Beta Pruning

  • Improves efficiency: Cuts down the number of nodes evaluated.

  • Same result as Minimax.

  • Best case complexity: O(b^(d/2)) instead of O(b^d) where:

    • b = branching factor

    • d = depth of the tree


Summary Table:

Term Meaning
α (Alpha) Best option for maximizer
β (Beta) Best option for minimizer
Prune Stop evaluating further when outcome is guaranteed to be worse