Min-max algorithm is a recursive or backtracking algorithm which is used in decision-making and game theory. Min-Max algorithm uses recursion to search through the game-tree. Min-Max algorithm is mostly used for game playing in AI. Such as Chess, Checkers, tic-tac-toe, go, and various tow-players game. This Algorithm computes the minimax decision for the current state. In this algorithm two players play the game, one is called MAX and other is called MIN. Both the players fight it as the opponent player gets the minimum benefit while they get the maximum benefit. Both Players of the game are opponent of each other, where MAX will select the maximized value and MIN will select the minimized value. The min-max algorithm performs a depth-first search algorithm for the exploration of the complete game tree.

### Pseudo Code

### Example

**Step-1:** In the first step, the algorithm generates the entire game-tree and apply the utility function to get the utility values for the terminal states. In the tree diagram, let's take A is the initial state of the tree. Suppose maximizer takes first turn which has worst-case initial value =- infinity, and minimizer will take next turn which has worst-case initial value = +infinity.

**Step 2:** Now, first we find the utilities value for the Maximizer, its initial value is -∞, so we will compare each value in terminal state with initial value of Maximizer and determines the higher nodes values. It will find the maximum among the all.

**Step 3:** In the next step, it's a turn for minimizer, so it will compare all nodes value with +∞, and will find the 3^{rd} layer node values.

**Step 4:** Now it's a turn for Maximizer, and it will again choose the maximum of all nodes value and find the maximum value for the root node. In this game tree, there are only 4 layers, hence we reach immediately to the root node, but in real games, there will be more than 4 layers.

### Properties of Mini-Max algorithm

**Complete-**Min-Max algorithm is Complete. It will definitely find a solution (if exist), in the finite search tree.**Optimal-**Min-Max algorithm is optimal if both opponents are playing optimally.**Time complexity-**As it performs DFS for the game-tree, so the time complexity of Min-Max algorithm is**O(b**, where b is branching factor of the game-tree, and m is the maximum depth of the tree.^{m})**Space Complexity-**Space complexity of Mini-max algorithm is also similar to DFS which is**O(bm)**.

### Limitation of the minimax Algorithm

The main drawback of the minimax algorithm is that it gets really slow for complex games such as Chess, go, etc. This type of games has a huge branching factor, and the player has lots of choices to decide. This limitation of the minimax algorithm can be improved from **alpha-beta pruning**.

## One Reply to “Min Max Search”