A Search and Min Mix Search

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Presentation

Presented To:
Mr. Asif Aziz

Presented By: Group 1


Name Roll No
Muhammad Waqas 1312
Muhammad Shakir 1314
Sana Ullah 1351
Bisma Gulzar 1359
Sundas Fatima 1363

GCUF Layyah Campus


What is an A* Algorithm?

 It is a searching algorithm that is used to find the shortest path between an


initial and a final point.

 It is a handy algorithm that is often used for map traversal to find the shortest
path to be taken. A* was initially designed as a graph traversal problem, to help
build a robot that can find its own course. It still remains a widely popular
algorithm for graph traversal.

 In A* search algorithm, we use search heuristic as well as the cost to reach the
node. Hence we can combine both costs as following, and this sum is called as
a fitness number.

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.

Problem-01:

Given an initial state of a 8-puzzle problem and final state to be reached-

Find the most cost-effective path to reach the final state from initial state using A*
Algorithm.
Consider g(n) = Depth of node and h(n) = Number of misplaced tiles.

Solution-

 A* Algorithm maintains a tree of paths originating at the initial state.


 It extends those paths one edge at a time.
 It continues until final state is reached.
Initial State

2 8 2 8 2 8

6 4 h=5 4 h=3
1+ 1+ 1+

2 8 2 8

4 h=3
2+4
7 6 6 5

2 8

4 h=4
3+ 3-«4 3+4
7 6

8 4 h=1

5+0
7 6

Final State
Problem-02:

Consider the following graph-

 The numbers written on edges represent the distance between the nodes.
 The numbers written on nodes represent the heuristic value.
 Find the most cost-effective path to reach from start state A to final state J using A*
Algorithm.
Solution-

Step-01:
 We start with node A.
 Node B and Node F can be reached from node A.

A* Algorithm calculates f(B) and f(F).


 f(B) = 6 + 8 = 14
 f(F) = 3 + 6 = 9

Since f(F) < f(B), so it decides to go to node F.

Path- A → F

Step-02:
Node G and Node H can be reached from node F.

A* Algorithm calculates f(G) and f(H).


 f(G) = (3+1) + 5 = 9
 f(H) = (3+7) + 3 = 13

Since f(G) < f(H), so it decides to go to node G.

Path- A → F → G
Step-03:
Node I can be reached from node G.

A* Algorithm calculates f(I).


f(I) = (3+1+3) + 1 = 8
It decides to go to node I.

Path- A → F → G → I

Step-04:
Node E, Node H and Node J can be reached from node I.

A* Algorithm calculates f(E), f(H) and f(J).


 f(E) = (3+1+3+5) + 3 = 15
 f(H) = (3+1+3+2) + 3 = 12
 f(J) = (3+1+3+3) + 0 = 10

Since f(J) is least, so it decides to go to node J.

Path- A → F → G → I → J
This is the required shortest path from node A to node J.
Advantages:
 Best first search can switch between BFS and DFS by gaining the
advantages of both the algorithms.
 This algorithm is more efficient than BFS and DFS algorithms.

Disadvantages:
 It can behave as an unguided depth-first search in the worst case scenario.
 It can get stuck in a loop as DFS.
 This algorithm is not optimal.
WHAT IS THE MINIMAX ALGORITHM?
 The Minimax Algorithm is a recursive or backtracking algorithm
typically used in turn-based, two-player games.
 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 minimax algorithm performs a depth-first search algorithm for the
exploration of the complete game tree.

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(bm), where b is branching factor of
the game-tree, and m is the maximum depth of the tree.
 Space Complexity- Space complexity of Mini-max algorithm is also similar
to DFS which is O(bm).

Limitation of the minimax Algorithm:


The biggest disadvantage of the minimax algorithm is that it becomes
extremely slow while playing complex games like chess or go. This style of game
contains a lot of branching, and the player has a lot of options to choose from. The
minimax algorithm's drawback can be alleviated by using alpha-beta pruning ,
which we will explore in the next section. the depth to which the tree can grow.
Problem:#

In the above figure, the two players MAX and MIN are there. MAX starts the
game by choosing one path and propagating all the nodes of that path. Now, MAX will
backtrack to the initial node and choose the best path where his utility value will be the
maximum. After this, its MIN chance. MIN will also propagate through a path and again
will backtrack, but MIN will choose the path which could minimize MAX winning
chances or the utility value.

You might also like