Artificial Intelligence & Neural Networks β Problem Solving and Searching Techniques, NEC licence examination syllabus (Nepal Engineering Council).
Alpha-Beta Pruning
Getting minimax's answer without examining minimax's tree.
π Where this lives: alpha-beta is one of the great practical results in computer science: it returns exactly the same move as minimax while examining a small fraction of the nodes. With good move ordering it effectively doubles the depth a program can reach in the same time β and in chess, each extra ply of depth is worth roughly 200 rating points. Deep Blue's ability to search 12 ply rather than 6 was alpha-beta, not hardware alone. Search "alpha beta pruning doubles search depth chess".
The idea and the algorithm
THE OBSERVATION: it is possible to compute the correct minimax
decision WITHOUT LOOKING AT EVERY NODE. Once you know enough about
a branch to be sure it cannot affect the decision, you can stop
examining it β PRUNE it.
TWO VALUES ARE CARRIED DOWN THE TREE during the search:
Ξ± (alpha) the value of the BEST (highest) choice found so
far at any choice point along the path for MAX.
"MAX can already guarantee at least Ξ±."
Ξ² (beta) the value of the BEST (lowest) choice found so
far along the path for MIN.
"MIN can already hold MAX to at most Ξ²."
ALPHA-BETA UPDATES Ξ± AND Ξ² AS IT GOES AND PRUNES A BRANCH AS
SOON AS THE VALUE OF THE CURRENT NODE IS KNOWN TO BE WORSE THAN
THE CURRENT Ξ± (for MAX) OR Ξ² (for MIN).
THE PRUNING CONDITION, in one line:
PRUNE WHEN Ξ± β₯ Ξ²
WHY IT IS SOUND β the reasoning that must be reproduced in an
exam:
At a MIN node, suppose MIN has already found a child worth 2,
so Ξ² = 2. MAX, higher up, has already secured Ξ± = 3
elsewhere. Whatever remains under this MIN node, MIN will
choose something β€ 2, which is worse for MAX than the 3
already guaranteed. SO MAX WILL NEVER COME HERE, and the
remaining children are irrelevant β their values cannot
change the decision. Prune them.
NOTE WHAT IS AND IS NOT CLAIMED: the pruned nodes might
contain excellent values. They are irrelevant because THE
PATH TO THEM WILL NOT BE TAKEN, not because they are bad.
THE ALGORITHM:
function ALPHA-BETA-SEARCH(state) returns an action
v β MAX-VALUE(state, ββ, +β)
return the action in ACTIONS(state) with value v
function MAX-VALUE(state, Ξ±, Ξ²) returns a utility value
if TERMINAL-TEST(state) then return UTILITY(state)
v β ββ
for each a in ACTIONS(state) do
v β MAX(v, MIN-VALUE(RESULT(state,a), Ξ±, Ξ²))
if v β₯ Ξ² then return v β Ξ²-CUTOFF
Ξ± β MAX(Ξ±, v)
return v
function MIN-VALUE(state, Ξ±, Ξ²) returns a utility value
if TERMINAL-TEST(state) then return UTILITY(state)
v β +β
for each a in ACTIONS(state) do
v β MIN(v, MAX-VALUE(RESULT(state,a), Ξ±, Ξ²))
if v β€ Ξ± then return v β Ξ±-CUTOFF
Ξ² β MIN(Ξ², v)
return v
THE KEY PROPERTY: ALPHA-BETA RETURNS THE SAME VALUE AND THE SAME
MOVE AS MINIMAX. It is not an approximation, not a heuristic,
and loses nothing. It is pure computational saving.
Worked trace, node by node
THE STANDARD TREE from the minimax topic:
branch A: 3, 12, 8 Β· branch B: 2, 4, 6 Β· branch C: 14, 5, 2
Root is MAX; each branch node is MIN. Search left to right.
START: root MAX, Ξ± = ββ, Ξ² = +β
ββ BRANCH A (a MIN node, inherits Ξ±=ββ, Ξ²=+β) βββββββββββββββ
leaf 3 β v = min(+β, 3) = 3. Is 3 β€ Ξ±(ββ)? No.
Ξ² β min(+β, 3) = 3
leaf 12 β v = min(3, 12) = 3. Ξ² stays 3
leaf 8 β v = min(3, 8) = 3
MIN(A) returns 3. ALL THREE LEAVES EXAMINED.
Back at the root: v = 3, Ξ± β max(ββ, 3) = 3
ββ BRANCH B (MIN node, inherits Ξ±=3, Ξ²=+β) ββββββββββββββββββ
leaf 2 β v = min(+β, 2) = 2.
IS v β€ Ξ±? 2 β€ 3 β YES. Ξ±-CUTOFF.
RETURN 2 IMMEDIATELY.
LEAVES 4 AND 6 ARE NEVER EXAMINED β 2 PRUNED.
WHY IT IS SAFE: MIN already has a 2 available here, so this
node's value is at most 2. MAX already has 3 from branch A.
MAX will never choose branch B, so its exact value does not
matter.
Back at the root: v = max(3, 2) = 3, Ξ± stays 3
ββ BRANCH C (MIN node, inherits Ξ±=3, Ξ²=+β) ββββββββββββββββββ
leaf 14 β v = 14. Is 14 β€ 3? No. Ξ² β 14
leaf 5 β v = min(14, 5) = 5. Is 5 β€ 3? No. Ξ² β 5
leaf 2 β v = min(5, 2) = 2. Is 2 β€ 3? YES β but it is the
last child anyway, so nothing remains to prune.
MIN(C) returns 2. ALL THREE LEAVES EXAMINED.
Back at the root: v = max(3, 2) = 3
RESULT: value 3, move A β IDENTICAL TO MINIMAX.
LEAVES EXAMINED: 7 of 9. Two pruned.
A SMALL SAVING ON A TINY TREE, and that is the honest point: the
saving grows explosively with depth, because a prune near the
root removes an entire subtree rather than two leaves.
THE EFFECT OF MOVE ORDERING β the decisive factor:
Suppose branch C had been searched FIRST, with its leaves
ordered 2, 5, 14:
MIN(C) sees 2 first, Ξ² = 2, and returns 2 after examining
all three (nothing to prune, since Ξ± is still ββ).
Ξ± at the root becomes 2.
Then branch A: leaf 3 β 3 > 2, no cutoff; 12, 8 β returns 3.
Ξ± becomes 3. Then branch B: leaf 2 β€ 3 β prune.
A DIFFERENT NUMBER OF NODES for the same tree and the same
answer. THE ORDER IN WHICH SUCCESSORS ARE CONSIDERED
DETERMINES HOW MUCH IS PRUNED.
IF WE COULD ORDER MOVES PERFECTLY β best first at every node β
alpha-beta examines only
O(b^(d/2)) nodes
instead of O(b^d). THAT MEANS THE EFFECTIVE BRANCHING FACTOR
BECOMES βb, WHICH DOUBLES THE SEARCHABLE DEPTH FOR THE SAME
COST.
THE ARITHMETIC, for chess with b = 35:
depth 8: full tree 35^8 β 2.25 Γ 10^12
perfect order 35^4 β 1.50 Γ 10^6
β a factor of about 1.5 million
depth 12: full tree 35^12 β 3.38 Γ 10^18
perfect order 35^6 β 1.84 Γ 10^9
RANDOM ORDERING gives about O(b^(3d/4)):
depth 8, random-ish 35^6 β 1.84 Γ 10^9
So even mediocre ordering is worth roughly a thousandfold at
depth 8, and good ordering another thousandfold on top.
IN PRACTICE, with reasonable ordering, chess programs come
fairly close to the b^(d/2) ideal β which is why alpha-beta plus
ordering, rather than raw hardware, is what made deep search
possible.
HOW MOVE ORDERING IS ACHIEVED β the standard techniques:
Β· try CAPTURES first, then threats, then forward moves
Β· the KILLER HEURISTIC: a move that caused a cutoff at the
same depth elsewhere is likely to cause one again
Β· ITERATIVE DEEPENING: the best move from the depth-(dβ1)
search is tried first at depth d. This is the most
effective method in practice, and it means the repeated
work of iterative deepening more than pays for itself
through better ordering.
Β· a TRANSPOSITION TABLE: cache the value of positions
already evaluated. Different move orders reach the same
position, and in chess the saving is very large.
Properties, and what pruning does not fix
PROPERTIES OF ALPHA-BETA:
CORRECTNESS returns exactly the minimax value and move
COMPLETENESS same as minimax
TIME O(b^(d/2)) with perfect ordering
O(b^(3d/4)) with random ordering
O(b^d) worst case (worst possible ordering)
SPACE O(bd) β unchanged; it is still depth-first
THE WORST CASE IS NO WORSE THAN MINIMAX, so alpha-beta is never
a loss. That is an unusually clean property for an optimisation.
TWO POINTS THAT ARE FREQUENTLY MISUNDERSTOOD:
1. PRUNING DEPENDS ON THE ORDER, NOT ON THE VALUES BEING GOOD.
A pruned subtree may contain the best position in the game.
It is pruned because THE OPPONENT WOULD NOT ALLOW THE PATH TO
IT, so its contents cannot change the decision.
2. Ξ± AND Ξ² ARE PROPERTIES OF THE PATH, NOT OF THE NODE. They are
inherited from ancestors and tightened as siblings are
examined. A node visited by a different path would have
different Ξ± and Ξ² β which is why a transposition table must
store the depth and the bound type alongside the value, not
merely the value.
WHAT ALPHA-BETA DOES NOT FIX:
Β· IT DOES NOT REMOVE THE NEED FOR AN EVALUATION FUNCTION. Even
at b^(d/2), chess to 80 ply is 35^40 β 10^61 nodes. The search
must still be cut off, and EVAL must still estimate.
Β· IT DOES NOT HELP GAMES WITH ENORMOUS BRANCHING FACTORS as
much. Go with b β 250 gives β250 β 16, which is still
unmanageable at useful depth β and worse, no good evaluation
function for Go was known. THAT COMBINATION IS WHY GO
RESISTED ALPHA-BETA ENTIRELY and needed Monte Carlo tree
search plus learned networks instead.
Β· IT DOES NOT ADDRESS THE HORIZON EFFECT OR QUIESCENCE, which
are properties of cutting off rather than of pruning.
Β· IT ASSUMES ZERO-SUM TWO-PLAYER PLAY. With three or more
players and utility vectors, the pruning argument breaks down
because a bad outcome for one player is not automatically good
for another.
RELATED PRUNING TECHNIQUES worth naming:
FORWARD PRUNING cut moves that look bad without proving
they are β unsound, but effective in
practice, and used by all strong
engines
NULL-MOVE HEURISTIC give the opponent a free move; if the
position is still good, it is probably
good enough to prune
LATE MOVE REDUCTION search moves ordered late to a shallower
depth
NOTE THAT THESE ARE ALL UNSOUND β they can prune the best
move. They are used anyway, because the depth bought is worth
more in practice than the occasional error. THAT IS AN
ENGINEERING JUDGEMENT, and it is the same trade as weighted A*
in the informed search topic: accept a bounded chance of
suboptimality in exchange for a large speed gain.
THE CLOSING SUMMARY OF THE WHOLE SEARCH SECTION: uninformed
search gives guarantees at exponential cost; heuristics cut the
cost by orders of magnitude; alpha-beta halves the exponent for
adversarial search; and when even that is not enough, the field
moved to sampling (MCTS) and learned evaluation. EACH STEP
TRADES SOMETHING β memory, optimality, or certainty β for
tractability.
The property that makes alpha-beta remarkable is that it costs nothing: it returns exactly minimax's move and value, its worst case is no worse than minimax, and with good ordering it halves the exponent. Optimisations that give up nothing at all are rare β most of the others in this syllabus trade memory, optimality or certainty for speed.
π Go further: Go's resistance to this entire approach is the most instructive story in game AI. With b β 250 even the βb of perfect alpha-beta leaves about 16, and β decisively β nobody could write a good positional evaluation function, because Go strength depends on whole-board shape rather than countable material. The answer was to stop evaluating and start sampling: Monte Carlo tree search plays thousands of random games from a position and uses the win rate as the estimate, needing no domain knowledge beyond the rules. AlphaGo then replaced the random playouts and the move selection with learned networks. Search "why Go was harder than chess MCTS evaluation function".
π‘ Exam angle: define Ξ± and Ξ² precisely and state the pruning condition Ξ± β₯ Ξ², with the Ξ±-cutoff and Ξ²-cutoff lines in the pseudocode. The guaranteed question is a trace: given a tree, work left to right, show the Ξ± and Ξ² values at each node, state which nodes are pruned and why, and confirm the answer matches minimax. Stress that alpha-beta returns the identical value and move. Give the complexities β O(b^(d/2)) with perfect ordering, O(b^(3d/4)) random, O(b^d) worst case β and explain that the effective branching factor becomes βb, doubling the searchable depth. Name the ordering techniques: captures first, killer heuristic, iterative deepening, transposition tables.
Syllabus points
Alpha-beta pruning (numerical)
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.
Related topics in Problem Solving and Searching Techniques