{"id":133,"date":"2026-11-13T12:32:18","date_gmt":"2026-11-13T04:32:18","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-alpha-beta-pruning-cuts-a-minimax-tree\/"},"modified":"2026-11-13T21:51:00","modified_gmt":"2026-11-13T13:51:00","slug":"how-alpha-beta-pruning-cuts-a-minimax-tree","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-alpha-beta-pruning-cuts-a-minimax-tree\/","title":{"rendered":"How alpha-beta pruning cuts a minimax tree"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>Alpha-beta pruning<\/strong> 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 <strong>O(b^{d\/2})<\/strong> instead of O(b^d). The value is identical to full minimax. The speed depends on move order.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The window [alpha, beta] travels down the tree. At the root it starts as (\u2212\u221e, +\u221e). A cutoff is sound only inside that window. Reordering moves does not change the value and changes how often the cutoff fires.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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&#8217;s best move as the first candidate, which is the usual way to approximate the perfect order.<\/p>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Call the root with alpha = \u2212\u221e and beta = +\u221e.<\/li>\n<li>At a maximizing node, track the best child value. For each child, raise alpha to the max of alpha and the child&#8217;s value. If alpha is at least beta, stop. The remaining children cannot change the parent&#8217;s decision.<\/li>\n<li>At a minimizing node, lower beta to the min of beta and the child&#8217;s value. If beta is at most alpha, stop.<\/li>\n<li>Pass the updated window to each child. Do not reset it to (\u2212\u221e, +\u221e) on the way down.<\/li>\n<li>Search the most promising move first. Iterative deepening, a hash move, or a killer heuristic are ways to guess that move.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when the search window is reset at every node<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Call every child with a fresh infinite window<\/td>\n<td>No cutoff information travels. The search is minimax with extra parameters that do nothing.<\/td>\n<\/tr>\n<tr>\n<td>Claim the square-root branching factor for arbitrary move order<\/td>\n<td>That bound is the perfect-order case. A bad order can evaluate every leaf.<\/td>\n<\/tr>\n<tr>\n<td>Skip a child of a chance node with the same test<\/td>\n<td>The average depends on every outcome. A cutoff needs bounds on the missing terms, not the plain alpha-beta test.<\/td>\n<\/tr>\n<tr>\n<td>Store a transposition as exact when it was only a cutoff<\/td>\n<td>A bound is not a value. Reusing it as exact corrupts the root.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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 <code>3<\/code>, and alpha-beta visits fewer leaves. It prints <code>3<\/code>.<\/p>\n\n<pre><code class=\"language-python\">leaves = [3, 5, 2, 9]\n\ndef minimax(i, depth, maximizing):\n    if depth == 2:\n        return leaves[i]\n    if maximizing:\n        return max(minimax(i * 2, depth + 1, False), minimax(i * 2 + 1, depth + 1, False))\n    return min(minimax(i * 2, depth + 1, True), minimax(i * 2 + 1, depth + 1, True))\n\nvisited = 0\n\ndef alphabeta(i, depth, alpha, beta, maximizing):\n    global visited\n    if depth == 2:\n        visited += 1\n        return leaves[i]\n    if maximizing:\n        value = -10**9\n        for child in (i * 2, i * 2 + 1):\n            value = max(value, alphabeta(child, depth + 1, alpha, beta, False))\n            alpha = max(alpha, value)\n            if alpha &gt;= beta:\n                break\n        return value\n    value = 10**9\n    for child in (i * 2, i * 2 + 1):\n        value = min(value, alphabeta(child, depth + 1, alpha, beta, True))\n        beta = min(beta, value)\n        if alpha &gt;= beta:\n            break\n    return value\n\nfull = minimax(0, 0, True)\npruned = alphabeta(0, 0, -10**9, 10**9, True)\nassert full == pruned == 3 and visited &lt; 4\nprint(pruned)\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\"><strong>Stockfish<\/strong> 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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for alpha-beta pruning returns the window cutoff and the perfect-order leaf bound it can achieve. <strong>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.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,39],"tags":[],"class_list":["post-133","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-games"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/133","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=133"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/133\/revisions"}],"predecessor-version":[{"id":532,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/133\/revisions\/532"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}