Algorithms Explained – minimax and alpha-beta pruning
In adversarial search, many branches are irrelevant. If the position is already not better than what we can get elsewhere, it is not worth exploring further. If the opponent can force a bad outcome, exploring good replies that the opponent will never allow is wasted work. So, we can prune subtrees that cannot affect the minimax decision.
Minimax explores about nodes, alpha-beta return the same minimax decision, but prunes branches that cannot affect the backed-up value. With good move ordering, the effective branching factor drops such that . In the best case:
Alpha and Beta Bounds
:
- Best (highest) value found so far for MAX
- Lower bound on what MAX can guarantee
- Increasing (non-decreasing) along a path
:
- Best (lowest) value found so far MIN
- Upper bound on what MIN can force
- Decreasing (non-increasing) along a path
Algorithm
- Perform depth-first minimax search.
- Maintain bounds along each path. Start at .
- At MAX nodes:
- Update
- Prune if
- At MIN nodes:
- Update
- Prune if
Alpha cutoff: While exploring a MIN node, if the current best values satisfies , then MAX already has an alternative guaranteeing at least . So MIN will never choose this branch, and we will prune the remaining children.
Beta cutoff: While exploring a MAX node, if the current best value satisfies , then MIN already has an alternative limiting MAX to at most . So, this branch cannot improve the outcome and the remaining children will be pruned.
Properties
- Complete: Yes (for finite game trees).
- Optimal: Yes (against an optimal opponent).
- Worst-case time: (same as minimax).
- Best-case time: with perfect move ordering.
- Space complexity: using depth-first search.
Comparison to Minimax
Alpha-beta returns the same optimal move/value, but fewer nodes are evaluated with pruning. However, the savings strongly depend on move ordering.
If good moves are explored first, rises quickly at MAX nodes and drops quickly at MIN nodes. Many siblings satisfy early. In the worst case, where bad moves are explored first, the bounds tighten slowly, with few/no cutoffs.
Thus, move-ordering heuristics are often used to sort children using a score that can be calculated quickly. Then we sort using the score, descending at MAX and ascending at MIN.

Examples
Video Example

Example 1
















Example 2






