How alpha-beta pruning cuts a minimax tree

Short answer: Alpha-beta pruning computes the same value as minimax and skips branches that cannot affect it. Alpha is the best value the maximizer can already force. Beta is the best value the minimizer can already force. A maximizing node stops when its value reaches beta. A minimizing node stops when its value falls to alpha. With the best move ordered first, the number of leaves is about O(b^{d/2}) instead of O(b^d). The value is identical to full minimax. The speed depends on move order.


What the problem actually asks

Minimax evaluates every child even after one child has already proved that the parent will never be chosen. If the maximizer has found a move worth at least alpha, the minimizer, one level above, will avoid this whole node once its value drops to alpha or below. Those children need not be searched. The symmetric cutoff applies on the other layer.

The window [alpha, beta] travels down the tree. At the root it starts as (−∞, +∞). A cutoff is sound only inside that window. Reordering moves does not change the value and changes how often the cutoff fires.


What the algorithm guarantees

The returned value equals the minimax value. A depth-first implementation uses O(d) memory. The O(b^{d/2}) leaf count holds for perfect ordering, where the best child is searched first at every node. Random order is less dramatic and still worthwhile. Worst-case order degenerates to full minimax. Extra bookkeeping for iterative deepening can supply a previous iteration’s best move as the first candidate, which is the usual way to approximate the perfect order.

The algorithm does not apply unchanged to expectiminimax. A chance node averages children, and skipping one changes the average. Pruning chance nodes needs bounds on the unexplored outcomes, which is a further technique.


The working steps

  1. Call the root with alpha = −∞ and beta = +∞.
  2. At a maximizing node, track the best child value. For each child, raise alpha to the max of alpha and the child’s value. If alpha is at least beta, stop. The remaining children cannot change the parent’s decision.
  3. At a minimizing node, lower beta to the min of beta and the child’s value. If beta is at most alpha, stop.
  4. Pass the updated window to each child. Do not reset it to (−∞, +∞) on the way down.
  5. Search the most promising move first. Iterative deepening, a hash move, or a killer heuristic are ways to guess that move.

The value matches minimax. The speed does not, unless the move order cooperates. A claim of b^{d/2} for an unordered legal-move generator overstates the pruning. Chance nodes are outside the basic cutoff. A transposition table is an optimization on top and must store the window for which an entry was exact.


Approaches that look simpler and fail

Approach Why it fails when the search window is reset at every node
Call every child with a fresh infinite window No cutoff information travels. The search is minimax with extra parameters that do nothing.
Claim the square-root branching factor for arbitrary move order That bound is the perfect-order case. A bad order can evaluate every leaf.
Skip a child of a chance node with the same test The average depends on every outcome. A cutoff needs bounds on the missing terms, not the plain alpha-beta test.
Store a transposition as exact when it was only a cutoff A bound is not a value. Reusing it as exact corrupts the root.

The unpruned backup is minimax. Sampling with rollouts is Monte Carlo tree search. Alpha-beta is exact minimax with sound cutoffs, at a speed that depends on move order.


A working example

This Python fragment passes the alpha-beta window down the tree and does not reset it at each node. The tree value matches minimax. With leaves 3, 5, 2, 9 under two layers of alternating max and min, both return 3, and alpha-beta visits fewer leaves. It prints 3.

leaves = [3, 5, 2, 9]

def minimax(i, depth, maximizing):
    if depth == 2:
        return leaves[i]
    if maximizing:
        return max(minimax(i * 2, depth + 1, False), minimax(i * 2 + 1, depth + 1, False))
    return min(minimax(i * 2, depth + 1, True), minimax(i * 2 + 1, depth + 1, True))

visited = 0

def alphabeta(i, depth, alpha, beta, maximizing):
    global visited
    if depth == 2:
        visited += 1
        return leaves[i]
    if maximizing:
        value = -10**9
        for child in (i * 2, i * 2 + 1):
            value = max(value, alphabeta(child, depth + 1, alpha, beta, False))
            alpha = max(alpha, value)
            if alpha >= beta:
                break
        return value
    value = 10**9
    for child in (i * 2, i * 2 + 1):
        value = min(value, alphabeta(child, depth + 1, alpha, beta, True))
        beta = min(beta, value)
        if alpha >= beta:
            break
    return value

full = minimax(0, 0, True)
pruned = alphabeta(0, 0, -10**9, 10**9, True)
assert full == pruned == 3 and visited < 4
print(pruned)

Where it is used

Stockfish and other chess engines search with alpha-beta pruning: a move that cannot beat the best line already found is cut off. Minimax without the bounds is the same tree and far too slow for a game clock. Monte Carlo tree search is the different idea used by AlphaGo.


When you can drop this algorithm

Drop unordered alpha-beta as a way to quote the b^{d/2} bound. Order the moves, or state the weaker saving. Keep the algorithm whenever a minimax value is required and some branches are already refuted by the window.


Why this stays published

We publish this so a search for alpha-beta pruning returns the window cutoff and the perfect-order leaf bound it can achieve. Alpha-beta pruning returns the minimax value and skips branches outside the current alpha-beta window, examining about b^{d/2} leaves when the best move is searched first.

本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。

Leave a Reply

Your email address will not be published. Required fields are marked *