Alpha-beta pruning is an optimization technique for minimax algorithms that reduces computation time by pruning branches that are provably non-optimal. It works by maintaining alpha and beta values that represent the best values found for the maximizing and minimizing players. Branches can be pruned when alpha is greater than or equal to beta, without affecting the optimal outcome. Alpha-beta pruning allows searching much deeper levels of the game tree in the same amount of time as minimax.
2. Agenda
■ Pruning
■ Introduction to Alpha-Beta Pruning
■ Nodes Representation
■ Rules for Alpha-Beta Pruning
■ Working
■ Pseudocode/Algorithm
■ Advantages over MIN-MAX
■ Heuristic Improvements
■ Application/Use
■ Conclusion
3. What Is Pruning?
■ Pruning means “to trim”.
■ An algorithm used to reduce the number of nodes to reach the optimal solution.
■ Works by blocking the evaluation of nodes.
■ Example:
– Alpha-Beta Pruning
4. Alpha-Beta Pruning
■ An optimization technique for mini-max algorithm.
■ Reduces the computation time by a huge factor.
■ Based on Depth First Search (DFS) searching technique.
■ Allows to search much faster and even go into deeper levels in the game tree.
■ Cuts off branches in the game tree which need not be searched.
■ Pruning is based on a base condition.
■ Keeps track of the best move for each side as it moves throughout the tree.
5. Alpha-Beta Pruning (Cont.)
■ It passes 2 extra parameters in the minimax function, namely alpha and beta.
■ Alpha is the value of the best (i.e., highest value) choice found for MAX, represented
as .
■ Beta is the value of the best (i.e., lowest value) choice found for MIN, represented as
.
■ Initial value of is -∞ (i.e. = -∞), worst value for MAX player.
■ Initial value of is +∞ (i.e. = +∞), worst value for MIN player.
■ Pruning is based on condition ≥ or ≤.
6. Nodes Representation
These are also called MAX nodes. The goal at a MAX node is to maximize the value of the
subtree rooted at that node. To do this, a MAX node chooses the child with the greatest
value, and that becomes the value of the MAX node.
These are also called MIN nodes. The goal at a MIN node is to minimize the value of the
subtree rooted at that node. To do this, a MIN node chooses the child with the least
(smallest) value, and that becomes the value of the MIN node.
= -∞
= +∞
≥-∞
≤+∞
Which is equivalent to
At the start of the problem, there is only the current state (i.e. the current position of pieces on the
game board). As for upper and lower bounds, it's a number less than infinity and greater than negative
infinity.Thus, here's what the initial situation looks like as above.
8. Rules for Alpha-Beta Pruning
■ For MIN node
– If β ≤ α of MAX ancestor, prune.
■ For MAX node
– If α ≥ β of MIN ancestor, prune.
■ Values of and cannot move upward the tree.
■ Values of and can move downward the tree.
■ Firstly find values of and & then find the value of Node.
■ Traverse the game tree from Left to Right.
9. Working of Alpha-Beta Pruning
■ Initialize alpha = -infinity and beta = infinity (i.e.
= -∞ and = ∞) as the worst possible cases. The
condition to prune a node is when alpha becomes
greater than or equal to beta (i.e. >=).
■ Start with assigning the initial values of alpha and
beta to root and since alpha is less than beta we
don’t prune it.
■ Carry these values of alpha and beta to the child
node on the left. And now from the utility value of
the terminal state, we will update the values of
alpha and beta.
■ Repeat the steps and wherever the condition
>= is satisfied prune that branch.
11. Psuedocode/Algorithm
alphabeta(root, no. of nodes, -∞, +∞,TRUE)//calling the function
function alphabeta(node, depth, a, b, maximizingPlayer)//returns heuristic values
if depth=0 or node is terminal node return the heuristic value of the node //base case
if maximizingPlayer isTRUE
{
for each child of the node
{
a= max(a, alphabeta(child, depth-1, a, b, FALSE)) //return Beta value from MIN player or heuristic value
if a ≥ b //condition for pruning
break //prune
}
return a
}
12. Psuedocode/Algorithm (Cont.)
else if maximizingPlayer is FALSE
{
for each child of the node
{
b= min(b, alphabeta(child, depth-1, a, b,TRUE)) //return Alpha value from MAX player or heuristic value
if a ≥ b //condition for pruning
break //prune
}
return b
}
14. Advantages over native Mini-Max
■ The benefit of alpha-beta pruning lies in the fact that branches of the search tree can
be eliminated.
■ The optimization reduces the effective depth to slightly more than half that of simple
minimax.
■ Alpha-Beta pruning can search a tree twice in the same time that mini-max takes to
search only once.
■ With perfect ordering, we attain time complexity O (b d/2)=O ( 𝑏 𝑑).
■ If b=40 (as in chess), and the search depth is 12 plies, the ratio between optimal and
sorting is a factor of nearly 406 or about 4 billion times.
15. Heuristic Improvements
■ Iterative deepening is usually used in conjunction with alpha-beta so that a reasonably
good move can be returned.
■ It searches at shallower depths give move-ordering hints that can help produce cutoffs
for higher depth searches much earlier than would otherwise be possible.
■ Uses best-first strategy that potentially makes them more time-efficient, but typically
at a heavy cost in space-efficiency.
■ Alpha-beta search can be made even faster by considering only a narrow search
window (generally determined by guesswork based on experience). This is known as
aspiration search.
16. Uses/Application of Alpha-Beta Pruning
■ It is an adversarial search algorithm used commonly for machine playing of two-player
games (Tic-tac-toe,Chess, Go, etc.).
■ It is used when a faster searching technique is required.
■ Efficiency is to be increased.
■ Time efficiency is to be decreased.
17. Conclusion
■ Two values are created during the search: alpha-value (associated with MAX nodes)
and beta-value (associate with MIN nodes). Pruning does not affect final results and
Entire subtrees can be pruned, not just leaves. With perfect ordering, we attain time
complexity O (b d/2) = O ( 𝑏 𝑑). Alpha-beta pruning can look twice as deep as minimax
in the same amount of time.