Adversarial Search: Minimax
Two perfect players, one game tree. MAX chases the largest value, MIN chases the smallest — back the values up and read the root.
What you'll learn
- In a two-player zero-sum game, MAX maximises the score and MIN minimises it
- The minimax value of a node = max of children at MAX, min of children at MIN
- Compute minimax bottom-up by recursion; leaves carry utility values
- Reading the root's optimal first move from the backed-up values
Before you start
Last lesson dropped you across a chessboard, where the old “cheapest path” frame fell apart: after every move you make, a second player makes the move that hurts you most. Minimax is the idea that makes reasoning against such an adversary precise. Two perfect players share one game tree; each plays the move best for them, knowing the other will do the same.
The crux is that you cannot plan only for yourself. Every plan you draft has to survive the opponent picking their best reply — so you read the tree backward from the leaves, score in hand, and let each player choose the child that matches their goal: the largest value for MAX, the smallest for MIN. This worst-case-aware reasoning is the backbone of every game-playing agent (chess and Go engines, poker bots) and of adversarial robustness in ML — anywhere you must act well against an opponent who answers your every move.
The minimax value
Formally, the minimax value V(n) of a node n:
V(n) = utility(n) if n is a leaf
V(n) = max over children c of V(c) if n is a MAX node
V(n) = min over children c of V(c) if n is a MIN node
That is the entire algorithm. Recurse to the leaves, then back the value up one level at a time. The root’s value is the score MAX can force against a perfectly playing MIN — the best result MAX can rationally hope for.
How GATE asks this
A typical NAT: a small game tree (often 2–3 levels, sometimes drawn as a MAX root with three strategies leading to MIN nodes of three leaves each). Compute the root’s minimax value, or state which strategy MAX should choose. Sometimes it is an MCQ asking “which strategy is optimal for MAX” — the same calculation, just read the index. This pattern appeared in GATE DA 2026.
Worked example — GATE DA 2026
MAX has three strategies, each leading to a MIN node with three leaf utilities:
- Strategy 1 leaves:
8, 6, -1- Strategy 2 leaves:
1, 5, 7- Strategy 3 leaves:
-4, -3, -12Which strategy should MAX play, and what is the game’s value?
Step 1 — back up MIN at each strategy node (MIN takes the smallest leaf):
- Strategy 1:
min(8, 6, -1) = -1 - Strategy 2:
min(1, 5, 7) = 1 - Strategy 3:
min(-4, -3, -12) = -12
Step 2 — MAX picks the largest of those:
V(root) = max(-1, 1, -12) = 1
So MAX plays strategy 2 and secures a value of 1 — the real GATE DA 2026 answer. Pause on the intuition: strategy 1 holds the highest individual leaf (8), but MIN will never let MAX reach it — MIN steers to the -1. Strategy 2’s worst case is 1, and MIN cannot do better than that, so the rational choice is strategy 2 even though its peak is lower. The shiniest leaf was a trap, exactly as the prompt hinted.
In one breath
Minimax solves a two-player zero-sum game by backing utility values up the game tree from the leaves: a MAX node takes the maximum of its children, a MIN node the minimum, so the root’s value is the score MAX can guarantee against a perfectly playing MIN; the optimal move is the child carrying that root value, and the classic trap is that the single biggest leaf is usually unreachable because MIN will steer away from it.
Practice
Quick check
A question to carry forward
Minimax is correct — and brutally expensive. To back up the root value it must, as written, examine every leaf of the game tree. For tic-tac-toe that is fine. For chess the tree has more leaves than there are atoms in the observable universe, and no machine will ever visit them all.
Yet stare at the worked example and a glimmer appears. Once MIN had found, under some strategy, a leaf bad enough, did MAX ever need to see that strategy’s remaining leaves? If one reply already drags a branch below something MAX can secure elsewhere, the rest of that branch cannot change MAX’s decision — so why look? Here is the thread onward: how do you prove, mid-search, that an entire subtree cannot possibly affect the root value, prune it away unexamined, and in the best case explore only the square root of the leaves minimax would — without changing the answer by even one?
Practice this in an interview
All questionsBinary search on the answer space (eating speed 1 through max pile size) rather than on the input array. For each candidate speed, greedily compute hours needed in O(n). The feasibility check is monotone — if speed k works, any speed above k also works — so binary search finds the minimum valid speed in O(n log m) time.
At each house you make one choice: rob it (and skip the previous) or skip it (and carry forward whatever you had). dp[i] = max(dp[i-1], dp[i-2] + nums[i]). Since you only look back two steps, two variables replace the full array, giving O(n) time and O(1) space.
Grid search exhaustively tries every combination in a predefined grid, which is only practical for 1–2 hyperparameters. Random search samples combinations uniformly at random and finds good values faster per compute budget, especially when only a few hyperparameters actually matter. Bayesian optimisation fits a surrogate model of the objective and proposes the next trial intelligently, giving the best sample efficiency for expensive evaluations.
Pruning removes splits that do not improve generalisation. Pre-pruning stops growth early via hyperparameters like max_depth or min_samples_leaf. Post-pruning (cost-complexity pruning) grows the full tree then collapses nodes whose removal does not hurt held-out accuracy enough.