Problem Solving&Searching Techniques
Problem Solving&Searching Techniques
Algorithm of A* search
• Step1: Place the starting node in the OPEN list.
• Step 2: Check if the OPEN list is empty or not, if the list is empty then
return failure and stops.
• Step 3: Select the node from the OPEN list which has the smallest value
of evaluation function (g+h), if node n is goal node then return success
and stop, otherwise
• Step 4: Expand node n and generate all of its successors, and put n into
the closed list. For each successor n', check whether n' is already in the
OPEN or CLOSED list, if not then compute evaluation function for n' and
place into Open list.
• Step 5: Else if node n' is already in OPEN and CLOSED, then it should
be attached to the back pointer which reflects the lowest g(n') value.
• Step 6: Return to Step 2.
• Complete: A* algorithm is complete as long as:
– Branching factor is finite.
– Cost at every action is fixed.
• Optimal: A* search algorithm is optimal if it follows below two
conditions:
• Admissible: the first condition requires for optimality is that h(n) should
be an admissible heuristic for A* tree search. An admissible heuristic is
optimistic in nature.
• Consistency: Second required condition is consistency for only A*
graph-search.
• If the heuristic function is admissible, then A* tree search will always find
the least cost path.
• Time Complexity: The time complexity of A* search algorithm depends
on heuristic function, and the number of nodes expanded is exponential to
the depth of solution d. So the time complexity is O(b^d), where b is the
branching factor.
• Space Complexity: The space complexity of A* search algorithm
is O(b^d)
Game Playing
• Game playing is a popular application of artificial intelligence that
involves the development of computer programs to play games, such
as chess, checkers, or Go.
• The goal of game playing in artificial intelligence is to develop
algorithms that can learn how to play games and make decisions that
will lead to winning outcomes.
• One of the earliest examples of successful game playing AI is the
chess program Deep Blue, developed by IBM, which defeated the
world champion Garry Kasparov in 1997.
• Since then, AI has been applied to a wide range of games, including
two-player games, multiplayer games, and video games.
• There are two main approaches to game playing in AI, rule-based
systems and machine learning-based systems.
– Rule-based systems use a set of fixed rules to play the game.
– Machine learning-based systems use algorithms to learn from
experience and make decisions based on that experience.
• The most common search technique in game playing is Minimax
search procedure. It is depth-first depth-limited search procedure.
It is used for games like chess and tic-tac-toe.
Minimax algorithm uses two functions
• MOVEGEN : It generates all the possible moves that can be
generated from the current position.
• STATICEVALUATION : It returns a value depending upon the
goodness from the viewpoint of two-player
• This algorithm is a two player game, so we call the first player as
PLAYER1 and second player as PLAYER2. The value of each node
is backed-up from its children. For PLAYER1 the backed-up value
is the maximum value of its children and for PLAYER2 the backed-
up value is the minimum value of its children. It provides most
promising move to PLAYER1, assuming that the PLAYER2 has
make the best move.
• It is a recursive algorithm, as same procedure occurs at each level.
Adversarial Search
• Adversarial search is a search, where we examine the problem
which arises when we try to plan ahead of the world and other
agents are planning against us.
• Searches in which two or more players with conflicting goals are
trying to explore the same search space for the solution, are
called adversarial searches, often known as Games.
• Games are modeled as a Search problem and heuristic evaluation
function, and these are the two main factors which help to model
and solve games in AI.
Types of Games in AI
• Imperfect information: If in a game agents do not have all
information about the game and not aware with what's going on, such
type of games are called the game with imperfect information, such as
tic-tac-toe, Battleship, blind, Bridge, etc.
• Deterministic games: Deterministic games are those games which
follow a strict pattern and set of rules for the games, and there is no
randomness associated with them. Examples are chess, Checkers, Go,
tic-tac-toe, etc.
• Non-deterministic games: Non-deterministic are those games which
have various unpredictable events and has a factor of chance or luck.
This factor of chance or luck is introduced by either dice or cards.
These are random, and each action response is not fixed. Such games
are also called as stochastic games.
Example: Backgammon, Monopoly, Poker, etc.
Minimax Search
• Mini-max algorithm is a recursive or backtracking algorithm which is
used in decision-making and game theory. It provides an optimal move
for the player assuming that opponent is also playing optimally.
• Mini-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 two-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 minimax algorithm performs a depth-first search algorithm for
the exploration of the complete game tree.
• The minimax algorithm proceeds all the way down to the terminal node
of the tree, then backtrack the tree as the recursion.
Alpha Beta Pruning
• Alpha-beta pruning is a modified version of the minimax
algorithm. It is an optimization technique for the minimax
algorithm.
• As we have seen in the minimax search algorithm that the
number of game states it has to examine are exponential in
depth of the tree. Since we cannot eliminate the exponent,
but we can cut it to half. Hence there is a technique by
which without checking each node of the game tree we can
compute the correct minimax decision, and this technique is
called pruning. This involves two threshold parameter
Alpha and beta for future expansion, so it is called alpha-
beta pruning. It is also called as Alpha-Beta Algorithm.
• Alpha-beta pruning can be applied at any depth of a tree,
and sometimes it not only prune the tree leaves but also
entire sub-tree.
• The two-parameter can be defined as:
– Alpha: The best (highest-value) choice we have found so
far at any point along the path of Maximizer. The initial
value of alpha is -∞.
– Beta: The best (lowest-value) choice we have found so far
at any point along the path of Minimizer. The initial value
of beta is +∞.
• The Alpha-beta pruning to a standard minimax
algorithm returns the same move as the standard
algorithm does, but it removes all the nodes which are
not really affecting the final decision but making
algorithm slow. Hence by pruning these nodes, it makes
the algorithm fast.