{ }
Initializing AlgoBuddy...
Optimizing your workspace
Optimizing your workspace
Observe how the Min Max algorithm discovers the optimal leaf node value!
Enter 8 comma-separated numbers for leaf nodes.
The Min Max algorithm is a recursive or backtracking algorithm used in decision-making and game theory. It provides an optimal move for the player assuming the opponent is also playing optimally.
Where b is the branching factor and d is depth.
The space is mainly consumed by the recursive call stack during the deep-first search traversal of the game tree.
// Min Max Algorithm in JavaScript
algorithm minimax(depth, nodeIndex, isMax, scores, h)
if depth = h thenreturn scores[nodeIndex]
if isMax then
return Math.max(
minimax(depth + 1, nodeIndex * 2, false, scores, h),
minimax(depth + 1, nodeIndex * 2 + 1, false, scores, h)
)
else
return Math.min(
minimax(depth + 1, nodeIndex * 2, true, scores, h),
minimax(depth + 1, nodeIndex * 2 + 1, true, scores, h)
)
// Usage example
scores ← [3, 5, 2, 9, 12, 5, 23, 23]
h ← Math.log2(scores.length)
result ← minimax(0, 0, true, scores, h)
console.log("Optimal value is: " + result)