Minimax examines every node, but many need not be examined. Alpha-beta pruning gives the same answer while skipping branches that cannot matter.

The Idea

Alpha-beta pruning is minimax with two bounds passed down the tree. α is the best value found so far for MAX along the path to the root (a lower bound, initially −∞); β is the best value found so far for MIN (an upper bound, initially +∞). At a node, if α ≥ β, the node cannot influence the final decision, because the player above already has a better alternative, so the remaining children are pruned (cut off). At a MAX node the value v is raised and α = max(α, v); at a MIN node v is lowered and β = min(β, v). The result at the root is identical to minimax; only the work is reduced.

Definition: Alpha-beta pruning. A refinement of minimax that skips (prunes) branches that cannot affect the final decision, using bounds α (best for MAX so far) and β (best for MIN so far) and cutting off when α ≥ β.

Effectiveness

The saving depends on move ordering. In the worst case the best moves are examined last and nothing is pruned: O(bᵐ), as for minimax. In the best case, with perfect ordering, the time is O(b^(m/2)), so the program can search twice as deep in the same time; for random ordering about O(b^(3m/4)). Good ordering heuristics (try captures first, killer moves, results of the previous iteration in iterative deepening) bring performance close to the best case. Deep Blue and all strong chess programs use alpha-beta with these refinements.

Worked Principle

Consider a MIN node whose first child has value 5, so β = 5. If another child of a MAX parent that already has α = 7 is being examined, the MIN node's value can only be ≤ 5, which MAX will never choose over 7; so its other children are skipped. Pruning therefore cuts off whole subtrees without evaluating them.

Table 2.7: Minimax and alpha-beta compared

Basis Minimax Alpha-beta
Result Optimal minimax value Same value
Nodes examined All Fewer (cut-offs)
Best-case time O(bᵐ) O(b^(m/2))
Depends on ordering No Yes

Example 2.7: Alpha-beta on the same tree

Problem: Apply alpha-beta to the tree with leaves 3, 5, 6, 9, 1, 2, 0, −1 (left to right).

Solution:

  1. First MAX node: leaves 3, 5 → value 5. First MIN node: β = 5.
  2. Second MAX node under it: leaf 6 gives v = 6 ≥ β = 5, so cut off; leaf 9 is pruned. MIN node value = 5; root α = 5.
  3. Second MIN node: first MAX child leaves 1, 2 → value 2; MIN β = 2 ≤ α = 5, so the second child (leaves 0, −1) is pruned.
  4. Leaves examined: 3, 5, 6, 1, 2 = 5 of 8.

Result: Root value 5 (same as minimax) using 5 leaf evaluations instead of 8.

leaves = [3, 5, 6, 9, 1, 2, 0, -1]
count = [0]
def ab(depth, i, is_max, a, b):
    if depth == 3:
        count[0] += 1
        return leaves[i]
    v = -99 if is_max else 99
    for k in (0, 1):
        r = ab(depth + 1, 2 * i + k, not is_max, a, b)
        if is_max:
            v = max(v, r); a = max(a, v)
        else:
            v = min(v, r); b = min(b, v)
        if a >= b:
            break
    return v
print("root value:", ab(0, 0, True, -99, 99))
print("leaves examined:", count[0], "of 8")

Output

root value: 5
leaves examined: 5 of 8

Common mistakes

  • Thinking pruning changes the minimax value; it never does.
  • Using the bounds the wrong way round (α for MIN, β for MAX).
  • Expecting large savings when moves are examined in poor order.
  • Cutting off when α > β only; the condition is α ≥ β.

Key takeaways

  • α = best for MAX so far; β = best for MIN so far; prune when α ≥ β.
  • Alpha-beta returns the same value as minimax with fewer nodes.
  • Best case O(b^(m/2)): double the search depth; worst case O(bᵐ).
  • Move ordering decides the effectiveness.

Practice questions

  1. When is a branch pruned in alpha-beta?
  2. Does alpha-beta change the final decision of minimax?
  3. What is the best-case time of alpha-beta?

Answers to the practice questions

  1. When α ≥ β, because the remaining children cannot affect the result.
  2. No, it gives the same minimax value.
  3. O(b^(m/2)).

Sources

  • Official BCA syllabus Artificial Intelligence, course code 26BCA404DS04, Unit II