Minimax Algorithm Theory Guide

Try the Minimax Algorithm Solver →
Intermediate11 min readLast Updated June 26, 2026
Prerequisites:Game Trees, Recursion Basics
Minimax AlgorithmGame TheoryArtificial IntelligenceZero-sum gamesMaximizerMinimizerGame Tree

Every time you have ever played a board game and thought 'okay, if I move here, they will move there, and then I am in trouble' — you were doing Minimax. It is the strategy of the cautious thinker: always assume your opponent will make the best possible move against you, then choose the path where that worst case hurts the least. Minimax is just a computer doing that same look-ahead, systematically, all the way to the end of the game.

  • The game is a tree: Every possible move branches into every possible response, which branches again, all the way down to a final outcome. Minimax maps this entire tree and scores every endpoint.
  • MAXMAX wants the highest score, MINMIN wants the lowest: One player is trying to win (maximize the score), the other is trying to make them lose (minimize it). Both players are assumed to play perfectly — no blunders, no luck.
  • The best move bubbles up from the bottom: Once every outcome is scored, the algorithm works back up the tree — MAXMAX picks the highest value available at each of their turns, MINMIN picks the lowest — until the root node reveals the single best move to make right now.

No guessing. No hoping the opponent slips up. Just the mathematically guaranteed best move, given a perfect opponent.

How to Trace Minimax by Hand

1

Label every level of the tree before writing a single number. The root node is always MAXMAX. The row below it is MINMIN, the row below that is MAXMAX, alternating all the way to the leaves. Write 'MAXMAX' and 'MINMIN' physically next to each row on your exam paper. If you skip this, you will inevitably apply the wrong logic at depth 3 and invalidate your entire trace.

2

Start at the root and go left-first using Depth-First Search. On your exam paper, trace the leftmost branch all the way down before touching anything else. You cannot assign a value to a parent node until every one of its children has been evaluated — so the leaves always get solved first.

3

At a leaf node, read and write its utility value. The exam question will give you these numbers. Write each value directly on the node — this is the raw score for that outcome. No calculation needed. Just read and label.

4

At a MINMIN node, look at all evaluated children and take the lowest value. MINMIN is trying to hurt MAXMAX as much as possible, so it always picks the move that results in the smallest score. Write that lowest value on the MINMIN node and pass it up.

5

At a MAXMAX node, look at all evaluated children and take the highest value. MAXMAX is trying to secure the best possible outcome, so it always picks the move that results in the largest score. Write that highest value on the MAXMAX node and pass it up.

6

Propagate all the way back to the root. Keep alternating — MINMIN takes the lowest, MAXMAX takes the highest — level by level, until the root node receives its final value. That number is the guaranteed optimal game score assuming both players play perfectly. The branch at the root with that value is the move MAXMAX should make.

The Recursive Minimax Formula

Minimax(s)={Utility(s)if s is a terminal statemaxaActions(s)Minimax(Result(s,a))if s is a MAX nodeminaActions(s)Minimax(Result(s,a))if s is a MIN node\text{Minimax}(s) = \begin{cases} \text{Utility}(s) & \text{if } s \text{ is a terminal state} \\ \max_{a \in \text{Actions}(s)}\, \text{Minimax}(\text{Result}(s, a)) & \text{if } s \text{ is a } MAX \text{ node} \\ \min_{a \in \text{Actions}(s)}\, \text{Minimax}(\text{Result}(s, a)) & \text{if } s \text{ is a } MIN \text{ node} \end{cases}

Breaking Down the Scary Notation

  • Utility(s)\text{Utility}(s) (The Base Case): If you hit the bottom of the tree (a terminal state), stop recursing. Utility(s)\text{Utility}(s) is just the raw score written on that leaf node. Read it and pass it straight up.
  • Actions(s)\text{Actions}(s) and Result(s,a)\text{Result}(s, a) (The Recursion): This looks intimidating, but it is just a formal way of saying 'look at my children'. Actions(s)\text{Actions}(s) means 'all the moves I can make'. Result(s,a)\text{Result}(s, a) just means 'the specific child node you get after making one of those moves'.
  • max\max (MAX's Turn): MAXMAX looks at the values returned by all of its children, assumes MINMIN will play perfectly from there, and simply grabs the highest number to secure the best outcome.
  • min\min (MIN's Turn): MINMIN looks at the values returned by all of its children, assumes MAXMAX will play perfectly, and maliciously grabs the lowest number to force the worst outcome.

Solved Example: Tracing Minimax by Hand

Draw this tree on paper before reading the steps. First, label the rows: write 'MAXMAX' next to the root level, and 'MINMIN' next to the level below it. The root (MAXMAX) has two children: Branch A (left) and Branch B (right). Branch A (MINMIN) has two leaf children: values 3 and 5. Branch B (MINMIN) has two leaf children: values 2 and 9. We always evaluate left to right, depth-first.

Step 1: Evaluate Branch A's leaves (left first)

Descend into Branch A. It is a MINMIN node. Read its two children: the left leaf is 3, the right leaf is 5. MINMIN controls this node and will always pick the move that hurts MAXMAX the most. Between 3 and 5, the lower value is 3. Branch A returns 3 upward to the root. Write 3 on Branch A.

Step 2: Evaluate Branch B's leaves

Descend into Branch B. It is a MINMIN node. Read its two children: the left leaf is 2, the right leaf is 9. Here is where most students make their first Minimax mistake — they see the 9 and assume MAXMAX should come here. Stop. MINMIN controls Branch B, not MAXMAX. MINMIN will never hand MAXMAX the 9. Between 2 and 9, MINMIN picks the lower value: 2. Branch B returns 2 upward to the root. Write 2 on Branch B.

Step 3: Resolve the root MAXMAX node

The root is a MAXMAX node. It now sees two options: Branch A returned 3, Branch B returned 2. MAXMAX picks the highest value available. Between 3 and 2, the higher value is 3. The root value is 3. Write 3 on the root. The optimal move for MAXMAX is to go to Branch A.

Step 4: The 'Aha' moment — why not Branch B?

Here is the exact reasoning to write on your exam if asked to justify this result. Branch B contains a 9, but MINMIN controls that node and will always force the 2. The best MAXMAX can ever realistically receive from Branch B is 2 — not 9. Branch A guarantees a 3 regardless of what MINMIN does, because MINMIN's best option there is already 3. Since 3>23 > 2, MAXMAX chooses Branch A. This is the core of Minimax: you do not chase the best possible outcome. You secure the best guaranteed outcome assuming your opponent plays perfectly against you.

See the Interactive Solver in Action

Now that you know how to trace it by hand, use the solver to verify your work instantly. Build your exact tree and watch values bubble up through alternating MAXMAX and MINMIN layers — every decision explained step by step.

Rules & Common Mistakes

  • Exam Trap: Never Trace Horizontally — Minimax Runs Depth-First
    The most common first mistake is trying to fill in an entire level before moving up. Students work across all the leaf nodes, then try to fill in every node on the next level up, and immediately get stuck. You cannot evaluate a parent until every one of its specific children is resolved — and those children may be on completely different branches. The only valid approach is vertical: plunge straight down the leftmost branch all the way to the leaves, resolve it fully, then move to the next branch. Treat it like a DFS call stack, not a spreadsheet you fill in row by row.
  • Exam Trap: The Highest Number in the Tree Is Not Always MAXMAX's Score
    Scan any Minimax tree and your eye will jump straight to the biggest leaf value. Do not chase it. If a MINMIN node sits directly above that leaf, MINMIN is the gatekeeper — and MINMIN will never hand MAXMAX the highest value on that branch. It will pick the lowest value available instead. You do not get the maximum number in the tree. You get the maximum value among the outcomes MINMIN is willing to allow. Always ask who controls the node above a leaf before assuming MAXMAX can reach it.
  • Exam Trap: Label Every Row Before You Write a Single Value
    By the time you reach depth 3 or 4, it is dangerously easy to forget whose turn it is and accidentally apply a MINMIN operation at a MAXMAX node — or vice versa. One wrong assignment cascades up the entire tree and invalidates your root value. The physical fix: before touching any numbers, take your pencil and write MAXMAX or MINMIN aggressively next to every single level of the tree. Do it first, do it clearly, and never skip it. It costs you ten seconds and saves you from throwing away correct leaf work on a labelling error.
  • Pro Tip: Depth-Limited Heuristic Values Are Just Leaf Values — Treat Them Identically
    Exam trees rarely run all the way to an actual win or loss. Most are cut off at depth 3 or 4 and use heuristic scores — estimated values a professor assigned to represent how good a position looks. Students see these and freeze, unsure whether the game is over or whether they need to do something extra. The rule is simple: it does not matter. Whether the number at the bottom of the tree is a real terminal utility or a heuristic estimate, your job is identical — read it, write it on the node, and pass it up. The Minimax logic above it does not change.

Strengths, Weaknesses & When To Use It

When to use it:In the real world, pure Minimax is almost never used in production — Alpha-Beta Pruning is a strict upgrade that finds the identical answer with far less work, so there is no reason to run the unoptimized version on a real game. The one place Minimax still gets used is tiny, trivial games like Tic-Tac-Toe, where the tree is so small that the inefficiency does not matter. On an exam, use Minimax when the question explicitly asks for an unoptimized trace, when you need to count the exact number of nodes a full tree evaluation visits, or when you are being asked to establish the worst-case baseline before introducing Alpha-Beta as an improvement.

Advantages

  • Mathematically Infallible: If the search reaches the end of the game tree, Minimax is guaranteed to find the absolute optimal move — no approximations, no guesses, no heuristic shortcuts. Every value at the root is a proven mathematical certainty given perfect play from both sides. On an exam, this means your traced root value is definitively correct as long as your MAXMAX and MINMIN operations are applied correctly at every node.
  • The Foundation of All Game AI: Minimax is the parent algorithm. Every advanced game AI concept you will encounter — Alpha-Beta Pruning, Expectimax, Monte Carlo Tree Search — is a direct modification of this exact alternating MAXMAX/MINMIN DFS logic. Master the mental model here and every follow-up algorithm becomes a minor tweak, not a new concept to learn from scratch.

Disadvantages

  • Exponential Node Explosion: Minimax runs in O(bm)O(b^m) time, where bb is the branching factor (number of children per node) and mm is the maximum tree depth. The number of nodes does not grow linearly — it multiplies at every single level. For Chess with b35b \approx 35, looking just 5 moves ahead requires evaluating over 50 million nodes. Looking 10 moves ahead is physically impossible on any hardware. The algorithm hits a computation wall almost immediately on any non-trivial game.
  • Zero Critical Thinking — Every Node Gets Evaluated: Minimax is completely blind to relevance. Even if the very first branch it explores hands the opponent an immediate winning position, it will still march through the entire remaining tree and evaluate every single node on the right side — just to confirm what was already obvious. There is no mechanism to recognize a branch is hopeless and skip it. Every node pays the same cost regardless of how useless it turns out to be.

Standard Minimax vs. Alpha-Beta Pruning

You cannot fully understand Alpha-Beta Pruning without first mastering Minimax — because they are the same algorithm at their core. The alternating MAXMAX and MINMIN recursion, the depth-first traversal, the value propagation from leaves to root — Alpha-Beta inherits all of it unchanged. The only thing Alpha-Beta adds is a memory of what has already been guaranteed on the current path. Minimax is the brute-force baseline that proves the logic works. Alpha-Beta is Minimax that learned to stop wasting time.

  • Evaluation Strategy: Minimax is exhaustive by design — it visits every single node in the tree without exception, regardless of what it has already found. Alpha-Beta is selective — the moment it can prove a branch cannot change the root decision, it stops expanding it entirely. Minimax sees everything. Alpha-Beta only looks at what matters.
  • Memory and State: Minimax is effectively memoryless — each node only cares about the values bubbling up from its immediate children, with no knowledge of what was secured higher up the tree. Alpha-Beta requires passing history downward — the α\alpha and β\beta bounds inherited from every ancestor on the current path. Minimax asks 'what do my children return?' Alpha-Beta asks 'what have my ancestors already guaranteed?'
  • Sensitivity to Move Ordering: Minimax is completely indifferent to move ordering — best moves on the left or right, it evaluates everything and always takes exactly O(bm)O(b^m) time. Alpha-Beta's efficiency is entirely dictated by ordering. Perfect ordering halves the exponent to O(bm/2)O(b^{m/2}); reverse ordering degrades it all the way back to O(bm)O(b^m). For Minimax, order is irrelevant. For Alpha-Beta, order is everything.
  • What Your Exam Is Actually Testing: If a professor asks you to trace Minimax, they are testing whether you understand the alternating MAXMAX/MINMIN recursive logic and can correctly propagate values from leaves to root. If they ask you to trace Alpha-Beta, they are testing whether you understand the boundary math — when α\alpha and β\beta cross and why a branch becomes irrelevant. The mechanics differ, but both algorithms return the exact same final answer at the root.

Implementation Pseudocode

// Minimax evaluates every node in the tree — no shortcuts, no skipping
// isMaximizing: true means it is MAX's turn, false means it is MIN's turn
// The function recurses all the way down to the leaves before any value is returned

function minimax(node, depth, isMaximizing):

    // BASE CASE: Reached a leaf node or the depth limit
    // Return the node's utility value directly — no comparison needed, just read and pass it up
    if depth == 0 or node is a terminal node:
        return node.value


    // ── MAX'S TURN ──────────────────────────────────────────────────────
    if isMaximizing:

        // Start at absolute floor — so low that the very first child value will always beat it
        // This guarantees bestValue gets replaced on the first comparison, never stays at -Infinity
        bestValue = -Infinity

        for each child in node.children:

            // Recurse into the child — it is now MIN's turn, so pass false
            childValue = minimax(child, depth - 1, false)

            // max(a, b): returns whichever value is higher
            // Replaces bestValue only if this child returned something better for MAX
            bestValue = max(bestValue, childValue)

        // Return the highest value found across all children
        return bestValue


    // ── MIN'S TURN ──────────────────────────────────────────────────────
    else:

        // Start at absolute ceiling — so high that the very first child value will always beat it
        // This guarantees bestValue gets replaced on the first comparison, never stays at +Infinity
        bestValue = +Infinity

        for each child in node.children:

            // Recurse into the child — it is now MAX's turn, so pass true
            childValue = minimax(child, depth - 1, true)

            // min(a, b): returns whichever value is lower
            // Replaces bestValue only if this child returned something better for MIN
            bestValue = min(bestValue, childValue)

        // Return the lowest value found across all children
        return bestValue


// ── INITIAL CALL (root is always MAX's turn) ─────────────────────────
// minimax(rootNode, maxDepth, true)

Time & Space Complexity

ScenarioTime ComplexitySpace ComplexityNotes
Time Complexity (All Cases)O(bm)O(b^m)O(m)O(m)Here bb = branching factor (number of children per node) and mm = maximum tree depth. The total number of nodes in the tree is bmb^m — and standard Minimax visits every single one of them, unconditionally. This is the exam trap to watch for: if a professor asks for the 'best-case' time complexity of Minimax, that is a trick question. There is no best case, worst case, or average case — they are all exactly O(bm)O(b^m). Minimax has zero mechanism to skip or prune nodes, so move ordering, tree shape, and leaf values are completely irrelevant to its time cost. It always does the same amount of work.
Space Complexity (DFS Stack)N/AO(m)O(m)Here is why the memory footprint stays manageable even though the time complexity explodes. Minimax uses Depth-First Search — at any given moment, it only needs to hold the current path from the root down to the active leaf node in memory. It does not store the entire tree at once. As soon as a branch is fully resolved and its value passed up, those nodes are discarded. Time scales exponentially with bmb^m, but memory only scales linearly with mm — the maximum depth of the tree.

Summary

Minimax isn't about hoping for the highest score — it is about surviving a perfect opponent. By alternating MAXMAX and MINMIN layers, the algorithm mathematically proves the best guaranteed outcome. However, this brute-force exhaustion hits a computational wall almost immediately, which is exactly why your syllabus will introduce Alpha-Beta Pruning next. True exam readiness means you can execute a strict left-first trace, proactively label your rows to avoid level confusion, and explain exactly why MAXMAX gets locked out of the highest leaf values. Once you stop just copying numbers and start seeing the adversarial gatekeeping at play, you have conquered the foundation.

Minimax Exam Questions Students Always Get Wrong

  • I can already see the winning move on the right side of the tree. Why do I have to trace the entire left side first?

    Because your exam is not testing whether you can spot a good move — it is testing whether you can trace like a computer. Minimax is blind. It has no vision of the whole tree; it just follows DFS rules mechanically, left branch first, every time. Trace left-first on your exam paper, even if it feels wasteful. Skipping to the right side is an automatic mark loss.

  • Why does MINMIN always pick the most negative number? Does MINMIN want a negative score?

    All scores in Minimax are calculated from MAXMAX's perspective — a high number means MAXMAX is winning, a low or negative number means MAXMAX is losing. MINMIN does not 'want' a negative score for its own sake. It picks the lowest number because that number represents MAXMAX's worst possible outcome. MINMIN's only goal is to make MAXMAX's life as difficult as possible.

  • What happens if MAXMAX or MINMIN has two children with identical values — which one does the algorithm pick?

    It picks the first one it found — which in a standard left-first DFS trace means the leftmost child. The final game score at the root will not change either way, since the values are identical. Stick to the leftmost path on your exam to match standard algorithm behaviour and avoid any ambiguity in your answer.

  • The tree on my exam ends at depth 3 but the game is not actually over yet. What am I supposed to do with those leaf values?

    Treat them exactly like a real win or loss — because for the purposes of this trace, they are. The leaf values are heuristic estimates of how good each position looks at that depth. Minimax does not care whether the game is truly over. Read the number, write it on the node, and pass it up. The math is identical either way.

Core University Curriculum

This algorithm and its manual calculation methods are foundational requirements in leading Computer Science and Software Engineering programs worldwide. You will find this topic heavily featured in the syllabi of these standard AI courses:

Explore Related Algorithms