AI Unit2 ProblemSolving
AI Unit2 ProblemSolving
Problem Solving
By
Dr. Mrudul Dixit
Problem-solving agent
• Formulate goal:
• be in Bucharest
• Formulate problem:
– states: various cities
– actions: drive between cities
• Find solution:
– sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
Well-defined problems and solutions
Initial State the initial state for our agent in Romania might be
described as In(Arad)
from the state In(Arad), the successor function for the Romania
Actions problem would return { (G o(Sibzu),I n(Sibiu)), (Go(T imisoara), In(
Tzmisoara)), (Go(Zerznd),I n(Zerind)))
State Space is the map of Romania with path as roads
Sudoku
Problem Solving
Approaches
• A toy problem is intended to illustrate or exercise various problem-solving methods.
• It can be given a concise, exact description.
• This means that it can be used easily by different researchers to compare the
performance of algorithms.
• Example Vaccum agent:
• This can be formulated as a problem as follows:
• States: The agent is in one of two locations, each of which might or might not
contain dirt. Thus there are 2 x 2^2 = 8 possible world states.
• Initial state: Any state can be designated as the initial state.
• Successor function: This generates the legal states that result from trying the three
actions (Left, Right, and Suck).
• Goal test: This checks whether all the squares are clean.
• Path cost: Each step costs 1, so the path cost is the number of steps in the path.
The state space for the vacuum world. Arcs denote actions: L = Left, R = Right, S =
Suck.
● State Space Search : Number of states in which the problem can go till it reaches
the goal state
● s : {S,A, Actions(s), Result(s,a), Cost(s,a)}
● S: various states namely start, goal and intermediate
● A: Set of all possible actions : up, down, left, right movement in puzzle problem
● Precise representation of 8 puzzle problem: 3 * 3 board has 9 spaces with 8
numbers on tiles and 1 is empty space
● As the intermediate state are created they will be compared with goal state and if
they match search is stopped
● Action(s) : is selected action out of available up down left or right
● Result(s,a): Resultant state after action is completed
● Cost(s,a): cost of moving to the next state
8 Puzzle problem
The 8-puzzle, consists of a 3 x 3 board with eight numbered tiles and a blank space.
A tile adjacent to the blank space can slide into the space. The object is to reach a
specified goal state, such as the one shown on the right of the figure.
The standard formulation is as follows:
• States: A state description specifies the location of each of the eight tiles and the
blank in one of the nine squares.
• Initial state: Any state can be designated as the initial state. Any given goal
can be reached from exactly half of the possible initial states
• Successor function: This generates the legal states that result from trying the
four actions (blank moves Left, Right, Up, or Down).
• Goal test: This checks whether the state matches the goal configuration
• Path cost: Each step costs 1, so the path cost is the number of steps in the path.
States: locations of tiles
Actions/operators: move blank left, right,
up, down
goal test: goal state (given)
path cost: 1 per move
• The 8-puzzle belongs to the family of sliding-block puzzles, which are often used
as test problems for new search algorithms in AI.
• This general class is known to be NP-complete ie. Nondeterministic Polynomial
time (is a complexity class used to classify decision problems.)
• The State Space of the (n^2 -1) problem has only half of these states are
reachable from any given state
• The 8-puzzle has 9!/2 = 181,440 reachable states ( total States are 9!)and is
easily solved.
• The 15-puzzle (on a 4 x 4 board) has around 1.3 trillion states, and random
instances can be solved optimally in a few milliseconds by the best search
algorithms.
• The 24-puzzle (on a 5 x 5 board) has around 10^25 states, and random instances
are still quite difficult to solve optimally with current machines and algorithms.
Initial State Final State
1 2 3 1 2 3
4 8 - 4 5 6
7 6 5 7 8 -
1 2 3 1 2 3 1 2 3 1 2 3
4 8 5 4 8 5 4 - 5 4 5 -
7 6 - 7 - 6 7 8 6 7 8 6
1 2 3 1 2 3
4 - 8 4 5 6
7 6 5 7 8 -
1 2 3 1 2 3 1 2 3 1 2 3
4 8 - 4 8 5 4 8 5 4 - 5
7 6 5 7 6 - 7 - 6 7 8 6
4 5 6 4 5 -
7 8 - 7 8 6
Initial State Final State
1 2 3 1 2 3
4 - 8 4 5 6
7 6 5 7 8 -
1 2 3 1 2 3 1 2 3 1 2 3
4 6 8 4 6 8 4 6 - 4 - 6
7 - 5 7 5 - 7 5 8 7 5 8
4 5 6 4 5 6
7 8 - 7 - 8
8 Queens Problem
• The goal of the 8-queens problem is to place
eight queens on a chessboard (8 by 8) such
that no queen attacks any other.
• Almost a solution of the 8-queens problem
but the queen in the first column is on the
same diagonal as the Queen in the last column.
Q1
Q1
Q2
Q2
Q4 Q3
Q4
Q3
Place the queens such that there is no queen in that row or column or in
diagonal
Q1
Q2
Q3
Q5
Q4
Q6
Q7
Q8
Q1
Q3
Q2
Q4
Q5
Q6
Q7
Q8
12 Unique Solutions
8-Queens Problem
8 Queens Problem
8 (X,Y | X+Y <=3^ (0,X+Y) {Pour all water from 4-gallon jug
X>0) into 3-gallon jug}
http://aimaterials.blogspot.com/p/blog-page_18.html
Initialization: Iteration 1: Iteration 4:
Start State: (0,0) Current State: (X,3) Current State : (4,2)
Apply Rule 2: Apply Rule 7: Apply Rule 3:
(X,Y | Y<3) -> (X,Y | X+Y<=4 ^Y>0) (X,Y | X>0)
(X,3) (X+Y,0) (0,Y)
{Fill 3-gallon jug} {Pour all water from 3-gallon jug {Empty 4-gallon jug}
Now the state is (X,3) into 4-gallon jug} Now state is (0,2)
Now the state is (3,0)
Iteration 5:
Current State : (0,2)
Iteration 2: Apply Rule 9:
Current State : (3,0) (0,2)
Apply Rule 2: (2,0)
(X,Y | Y<3) -> {Pour 2 gallon water from 3 gallon
(3,3) jug into 4 gallon jug}
{Fill 3-gallon jug} Now the state is (2,0)
Now the state is (3,3)
Goal Achieved.
Iteration 3:
Current State:(3,3)
Apply Rule 5:
(X,Y | X+Y>=4 ^ Y>0)
(4,Y-(4-X))
{Pour water from 3-gallon jug into
4-gallon jug until 4-gallon jug is full}
Now the state is (4,2)
State Space Tree:
https://www.eecis.udel.edu/~mccoy/courses/cisc4-681.10f/lec-materials/handouts/search-water-jug-handout.pdf
Real World Problems: Route Finding Problem
• Route-finding algorithms are used in a variety of applications, such as routing in
computer networks, military operations planning, and airline travel planning
systems.
• These problems are typically complex to specify.
• Example of an airline travel problem :
• States: Each is represented by a location (e.g., an airport) and the current time.
• Initial state: This is specified by the problem.
• Successor function: This returns the states resulting from taking any scheduled
flight (perhaps further specified by seat class and location), leaving later than the
current time plus the within-airport transit time, from the current airport to another.
• Goal test: Are we at the destination by some prespecified time
• Path cost: This depends on monetary cost, waiting time, flight time, customs and
immigration procedures, seat quality, time of day, type of airplane, frequent-flyer
mileage awards, and so on.
Real World Problems: Route Finding Problem
• Commercial travel advice systems use a problem formulation of this kind, with
many additional complications to handle the fare structures that airlines impose.
• Any seasoned traveller knows, however, that not all air travel goes according to
plan.
• A really good system should include contingency plans-such as backup
reservations on alternate flights to the extent that these are justified by the cost and
likelihood of failure of the original plan.
Real World Problems: Travelling Salesperson Problem
• Search techniques used are an explicit search tree that is generated by the initial
state and the successor function that together define the state space.
• A search graph will be used rather than a search tree, when the same state can be
reached from multiple paths
• The root of the search tree is a search node corresponding to the initial state
•
Search Solutions
• Example : finding a route from Arad to Bucharest.
• Initial State :In Arad
• The first step is to test whether this is a goal state.
• Its not so not a goal state, we need to consider some other states.
• This is done by expanding the current state i.e. applying the successor
function to the current state thereby generating a new set of states.
• In this case, we get three new states: In(Sibiu), In(Timisoara), and In(Zerind)
• Every time we have to check whether its a goal state or not, if not ,expand the
current state
• The choice of which state to expand is determined by the search strategy by
using general tree-search algorithm
Search Solutions
• It is important to distinguish between the state space and the search tree.
• For the route finding problem, there are only 20 states in the state space, one for
each city.
• But there are an infinite number of paths in this state space, so the search tree
has an infinite number of nodes.
• For example, the three paths Arad-Sibiu, Arad-Sibiu-Arad, Arad-Sibiu-Arad-Sibiu
are the first three of an infinite sequence of paths.
• A good search algorithm avoids such repeated paths
• A node is a data structure with five components:
• STATE: the state in the state space to which the node corresponds;
• PARENT-NODE: the node in the search tree that generated this node;
• ACTION: the action that was applied to the parent to generate the node;
• PATH-COST: the cost, traditionally denoted by g ( n ) , of the path from the initial
state to the node, as indicated by the parent pointers; and
• DEPTH: the number of steps along the path from the initial state.
• A node is a bookkeeping 'data structure used to represent the search tree.
• A state corresponds to a configuration of the world
Search Solutions
• A node is a bookkeeping 'data structure used to represent the search tree.
• A state corresponds to a configuration of the world
• Nodes are on particular paths, as defined by PARENT-NODE pointers, whereas
states are not.
• Two different nodes can contain the same world state, if that state is generated via
two different search paths.
• The collection of nodes that have been generated but not yet expanded-this
collection is called the fringe.
• Each element of the fringe is a leaf node i.e. a node with no successors in the
tree.
• The collection of nodes is implemented as a queue
Search Solutions
• The operations on a queue are as follows:
• Make Queue (Elements ) Creates a queue with the given element(s).
• Empty (queue) returns true only if there are no more elements in the queue.
• First(queue) returns the first element of the queue.
• Remove First (queue): returns first (queue) and removes it from the queue.
• Insert (Element, queue) inserts an element into the queue and returns the resulting
• queue. (
• Insert ALL (Elements, Queue) inserts a set of elements into the queue and returns
the resulting queue
•
Performance measure for Problem Solving
• Linear Search :
• https://www.geeksforgeeks.org/linear-search/
• https://www.hackerearth.com/practice/algorithms/searching/linear-search/tut
orial/#:~:text=Linear%20search%20is%20used%20on,all%20the%20element
s%20with%20value%20.
• Binary Search :
• https://www.geeksforgeeks.org/binary-search/
• https://www.tutorialspoint.com/data_structures_algorithms/binary_search_al
gorithm.htm#:~:text=Binary%20search%20looks%20for%20a,left%20of%20
the%20middle%20item.
Uninformed Search or Blind Search Strategies
• Breadth-first search:
• It is a simple strategy in which the root node is expanded first, then all the
successors of the root node are expanded next, then their successors, and so
on.
• All the nodes are expanded at a given depth in the search tree before any nodes at
the next level are expanded.
• Breadth-first search is implemented by calling TREE-SEARCH with an empty
fringe that is a first-in-first-out (FIFO) queue, assuring that the nodes that are
visited first will be expanded first.
• The FIFO queue puts all newly generated successors at the end of the queue,
which means that shallow nodes are expanded before deeper nodes.
•
Uninformed Search or Blind Search Strategies
Depth 0 : root
Depth is edges between the targeting node and the root
Edge – connection between one node to another.
2
3 • Time and space complexity = O(b d+1)
4 5 6 7
• b =2 d=2 Time complexity = 2 2+1 = 2 3 =8
https://www.google.com/search?q=breadth+first+search+algorithm&source=lnms&tbm=vid&sa=X&ved=2ahUKEw
jVssmggLf7AhXTcGwGHZpeCcoQ_AUoAnoECAEQBA&biw=1443&bih=742&dpr=0.9#fpstate=ive&vld=cid:04112
a3f,vid:QRq6p9s8NVg
http://artificialintelligence-notes.blogspot.com/2010/07/8-puzzle-problem.htm
https://www.youtube.com/watch?v=_CrEYrcImv0
https://www.tutorialspoint.com/data_structures_algorithms/breadth_first_traversal.htm#:~:text=Breadth%20First%2
0Search%20(BFS)%20algorithm,and%20G%20lastly%20to%20D.
https://www.youtube.com/watch?v=_CrEYrcImv0
http://artificialintelligence-notes.blogspot.com/2010/07/8-puzzle-problem.htm
Uninformed Search or Blind Search Strategies
• Depth-first search :
• Depth-first search always expands the deepest node in the current fringe of
the search tree
• The search proceeds immediately to the deepest level of the search tree, where the
nodes have no successors.
• As those nodes are expanded, they are dropped from the fringe, so then the
search "backs up" to the next shallowest node that still has unexplored successors.
• It can be implemented by
– TREE-SEARCH with a last-in-first-out (LIFO) queue, also known as a stack.
– depth-first search with a recursive function that calls itself on each of its children
in turn.
• Depth-first search has very modest memory requirements
• It needs to store only a single path from the root to a leaf node, along with the
remaining unexpanded sibling nodes for each node on the path
• Once a node has been expanded, it can be removed from memory as soon as all
its descendants have been fully explored
Depth-first search
• Implementation:
• fringe = LIFO queue, i.e., put successors at front
Depth-first search
B G H
C F I L
E J K
D
Uninformed Search or Blind Search Strategies
• Depth-first search :
http://artificialintelligence-notes.blogspot.com/2010/07/8-puzzle-problem.htm
depth-first search
• A variant of depth-first search called backtracking search uses still less
memory than DFS
• In backtracking, only one successor is generated at a time rather than all
successors; each partially expanded node remembers which successor to
generate next.
• In this way, only O(m) memory is needed rather than O(bm)…. b branching
factor , Max. depth m
• Backtracking search facilitates memory saving (and time-saving) trick: the
idea of generating a successor by modifying the current state description
directly rather than copying it first.
• This reduces the memory requirements to just one state description and O(m)
actions.
• For this to work, we must be able to undo each modification when we go back
to generate the next successor.
• The drawback of depth-first search is that it can make a wrong choice and
get stuck going down a very long (or even infinite) path when a different
choice would lead to a solution near the root of the search tree.
Depth Limited search
• Depth first search has some desirable properties — space complexity.
• But if wrong branch expanded (with no solution on it), then it may not
terminate.
– the cut off value indicates no solution within the depth limit.
Depth Limited search
• Depth-limited Search :The problem of unbounded trees can be solved by
supplying depth-first search with a predetermined depth limit l.
• The nodes at depth l are treated as if they have no successors.
• This approach is called depth-limited search.
• But it also introduces incompleteness if we choose t < d, i.e. the shallowest
goal is beyond the depth limit.
• Depth-limited search will also be non-optimal if we choose l > d.
• Its time complexity is O(b ^ l ) and its space complexity is O(bm).
• Depth-first search can be viewed as a special case of depth-limited search with
l= infinity.
•
Depth Limited search
• Example:
• On the map of Romania there are 20 cities.
• But fact is that any city can be reached from any other city at most in 9
steps.
• This number is the diameter of the state space and gives the depth limit,
• For most problems, good depth limit is not known until problem is solved.
Depth Limited search
• The unbounded tree problem appeared in Depth First Search can be fixed by
imposing a limit on the depth that DFS can reach, this limit is depth limit
• Depth Limited Search solves the infinite path problem
• Performance Measure:
– Completeness: DLS is not complete when depth limit(l) is less than depth
(d) Then DLS will never reach a goal,
– Optimality: DLS is not optimal even if l > d.
– Time Complexity: O(b^ l )
– Space Complexity: O(bm )
• DLS can be used when the there is a prior knowledge to the problem and that
the depth of shallowest goal is known
•
Iterative deepening depth-first search
Data structure BFS uses Queue to find the DFS uses Stack to find the shortest path.
1 shortest path.
Source BFS is better when target is DFS is better when target is far from source.
2 closer to Source.
Suitability for As BFS considers all neighbour DFS is more suitable for decision tree. As
decision tree so it is not suitable for decision with one decision, we need to traverse further
3 tree used in puzzle games. to augment the decision. If we reach the
conclusion, we won.
•
Search and exploration
• Best first search is an instance of graph search algorithm in which a node is
selected for expansion based on evaluation function f (n).
• The node which is the lowest evaluation is selected for the explanation
because the evaluation function measures distance to the goal.
• Best first search can be implemented using a priority queue, a data structure
that will maintain the fringe in ascending order of f values.
• This search algorithm serves as combination of depth first and breadth first
search algorithm.
• Best first search algorithm is often referred greedy algorithm this is because
they quickly attack the most desirable path as soon as its heuristic weight
becomes the most desirable.
•
Best-First Search
Minimum Cost is heuristic function so D is selected, and successors are generated,
search goes to E and F but they have higher cost than B and C so The search
shifts to B
A A A
B C D B C D
3 5 1 3 5
E F
4 6
A A
B C D B C D
5 5
G H E F G H E F
6 5 4 6 6 5 6
I J
2 1
Search and exploration
• There are many variations of Best first search algorithms with different
evaluation functions called as heuristic function h(n)
• h(n) is estimated cost of the cheapest path from node n to a goal node.
• Greedy Best first search, A*, etc. are variations in Best Search algorithms
• Example : In a route finding problem that 'straight line' distance from the node
to the goal can be used to evaluate each node.
● For example, in Romania, one might estimate the cost of the cheapest
path from Arad to Bucharest via the straight-line distance from Arad to
Bucharest.
•
Search and exploration
• Best-first search
• The worst case time complexity for Best First Search is O(n * Log n)
where n is number of nodes. In worst case, we may have to visit all nodes
before we reach goal.
• The priority queue is implemented using Min(or Max) Heap, and insert and
remove operations take O(log n) time.
• Performance of the algorithm depends on how well the cost or evaluation
function is designed.
• A priority queue is an abstract data type similar to a regular queue or stack
data structure in which each element additionally has a "priority" associated
with it. In a priority queue, an element with high priority is served before an
element with low priority.
• While priority queues are implemented with heaps
• A priority queue is a concept like "a list" or "a map"; just as a list can be
implemented with a linked list or an array, a priority queue can be
implemented with a heap
•
100 10 5
A B D F
● There are 2 lists made open list and
20 60 10 close list.
50 20 ● When a Node is expanded and node
connecting to shortest heuristic
S C E G distance it goes into closed list
50 100 10
So the Best Path from source to goal is in close list and is A,C,D,F,G and the path cost is 105
Search and exploration
• Greedy best-first search :
• It tries to expand the node that is closest to the goal, on the grounds that
this is likely to lead to a solution quickly.
• It evaluates nodes by using just the heuristic function: f (n) = h(n).
• The algorithm is called greedy as at each step it tries to get as close to the
goal as it can.
• Greedy best-first search resembles depth-first search
• It follow a single path to the goal, but will back up when it hits a dead end.
• It is not optimal like the depth first search
• Completeness : It is incomplete as it can move on to infinite path and never
try the other possibilities
• The worst-case time and space complexity is O(b m), where m is the
maximum depth of the search space.
• But with a good heuristic function the complexity can be reduced
Romania with step costs in km
Greedy best-first search example
Greedy best-first search example
Greedy best-first search example
Greedy best-first search example
Straight line distance : hSLD
Search and exploration
• Greedy Best First Search Algorithm Properties:
• Time Complexity : O(bm), but a good heuristic can give dramatic improvement
• Optimal : No
• https://www.youtube.com/watch?v=dv1m3L6QXWs
•
Search and exploration
• A* search (A Star):
• * (star) in the A* algorithm means that the algorithm is admissible, i.e. it is guaranteed
that it finds the shortest path in the graph if this path exists
• A * algorithm is a searching algorithm that searches for the shortest path between the
initial and the final state. It is used in various applications, such as maps.
• In maps the A* algorithm is used to calculate the shortest distance between the source
(initial state) and the destination (final state).
Search and exploration
• A* search (A Star): Minimizing the total estimated solution cost
• It is most widely know best-first search, it avoids expanding paths that are already
expensive
• It evaluates nodes by combining the cost to reach the node g(n) and the cost to get
from the node to the goal h(n)
• f(n) = g(n)+h(n) where
– g(n) gives the path cost from the start node to node n
– h(n) is the estimated cost of the cheapest path from n to the goal
– f (n) is estimated cost of the cheapest solution through n
• To find the cheapest solution the node with the lowest value of g(n) + h(n) is
selected
• It is good strategy if the heuristic function h(n) satisfies certain conditions
• A* search is both complete and optimal.
• A* is optimal if h(n) is an admissible heuristic i.e h(n) never overestimates the cost to
reach the goal i.e. optimistic
• Admissible heuristics are by nature optimistic, because they think the cost of solving
the problem is less than it actually is.
• Since g(n) is the exact cost to reach n so f (n) never overestimates the true cost of a
solution through n.
*
A search example
Stages in an A* search for Bucharest. Nodes are labelled with f = g + h. G is distance from one
node to another H is straight line distance
Sibiu = 140+253 140 = Arad to Sibiu straight distance from Sibiu to Bucharest =253
*
A search example
417+0
● Optimal : Yes
• https://www.google.com/search?q=A*+algorithm+video&oq=A*+algorithm+vid
eo&aqs=chrome..69i57j0i22i30.5370j0j7&sourceid=chrome&ie=UTF-8#fpstat
e=ive&vld=cid:7ab1a285,vid:-L-WgKMFuhE
• https://www.javatpoint.com/ai-informed-search-algorithms
• https://www.google.com/search?q=depth++first+search+algorithm+with+example+puzzle&biw=1443&bih=742&tbm=vid&ei=eh
l3Y9-xMpiOseMPxfSpyAM&ved=0ahUKEwjf1qmEgbf7AhUYR2wGHUV6CjkQ4dUDCA0&uact=5&oq=depth++first+search+
algorithm+with+example+puzzle&gs_lcp=Cg1nd3Mtd2l6LXZpZGVvEAMyBQghEKABMgUIIRCgAToECAAQQzoFCAAQgA
Q6CAgAEBYQHhAPOgYIABAWEB46BQgAEIYDOggIIRAWEB4QHToHCCEQoAEQCjoECCEQFVC_B1jMRWDSUGgAc
AB4AIAB0wGIAZEVkgEGMC4yMC4xmAEAoAEBwAEB&sclient=gws-wiz-video#fpstate=ive&vld=cid:1a89ceb2,vid:dvWk0
D
Cost from Node to HEURISTIC h(n)
Node g(n)
A B S 7
S-A 1
A 6
S-B 4
B 2
A-B 2
S C C 1
A-C 5
D 0
A-D 0
B-C 2
C-D 3
1 S 4 HEURISTIC h(n)
2 S 7
A B
A 6
2
12 5 B 2
C 1
D C
3 D 0
● S->A = 7
● S->B = 6 … SELECT THIS
● EXPAND B
● S->B->C = 7 COST OF S->A AND S->B->C = 7 GO ANOTHER ROUTE
● S->A : S->A->B=5 S->A->C=7 S->A->D=13 PATH 4
● S->A->B=5 WHICH IS LESS THAN S->B->C = 7 SO EXPAND B NODE
● S->A->B->C =6 EXPAND C
● S->A->B->C->D =8 PATH 1 PATH COST GREATER S->B->C = 7 SO EXPAND C
● S->B->C->D = 9 PATH 2 THIS GREATER THAN S->A->C=7 EXPAND C
● S->A->C->D = 9 PATH 3
● sHORTEST PATH IS S->A->B->C->D =8
1 S 4
Cost from Node to HEURISTIC h(n)
2 Node g(n)
A B S 7
S-A 1
2 A 6
12 5 S-B 4
B 2
A-B 2
D C C 1
3 A-C 5
D 0
A-D 0
Start Node : S Goal Node : D
B-C 2
f(n) = g(n) + h(n)
C-D 3
● WE HAVE 4 PATHS :
● S=0+7 =7 … START NODE HAS HEURISTIC SO WILL HV ESTIMATED COST
● S -> A = 1 +6 = 7 ….. heuristic of the child node will be taken
● S -> B = 4 + 2 =6 Select shortest path so select S -> B and expand and go to child nodes of B
● S -> B -> C = (4 +2 )+ 1 =7 ….. S-> A = 7 and S -> B -> C = 7 so we will check the other route
● S -> B -> C->D = (4 +2+3 )+ 0 =9
● S -> A->B = (1+2)+2 =5
● S -> A->C = (1+5)+1 =7
● S -> A->D = (1+12)+0 =13 ….. S -> A->B IS SHORTEST DISTANCE SO EXPAND THIS
● S -> A->B->C = (1+2+2) + 1 =6 … ONLY ONE PATH SO EXPAND TO D
● S -> A->B->C->D = (1+2+2+3)+0 = 8
● S->A->C->D = (1+5+3)+0 = 9
1 S 4
Cost from Node to HEURISTIC h(n)
2 Node g(n)
A B S 7
S-A 1
2 A 6
12 5 S-B 4
B 2
A-B 2
D C C 1
3 A-C 5
D 0
A-D 0
Start Node : S Goal Node : D
B-C 2
f(n) = g(n) + h(n)
C-D 3
• At each iteration, the cutoff value is the smallest f-cost of any node that
exceeded the cutoff on the previous iteration.
• IDA* is practical for many problems with unit step costs and avoids the
substantial overhead associated with keeping a sorted queue of nodes.
•
Search and exploration
• Memory-bounded algorithms: RBFS
• Recursive best-first search (RBFS) is a simple recursive algorithm works
like standard best-first search using only linear space
• It keeps the track of f-value of the best alternative path available from
ancestor of current node
• If the current node exceeds the limit, the recursion unwinds back to the
alternative path.
• As the recursion unwinds, RBFS replaces the f -value of each node along the
path with the best f -value of its children.
• In this way, RBFS remembers the f -value of the best leaf in the forgotten
subtree and can therefore decide whether it's worth re-expanding the sub
tree at some later time
• RBFS is somewhat more efficient than IDA*, but still suffers from excessive
node regeneration.
Search and exploration
• Memory-bounded algorithms: RBFS and MA*
• RBFS changes the path (mind) depending on the F-cost function
• These mind changes occur because every time the current best path is
extended, there is a good chance that its f -value will increase, h is usually less
optimistic for nodes closer to the goal.
• When this happens, particularly in large search spaces, the second-best path
might become the best path, so the search has to backtrack to follow it.
• Each mind change corresponds to an iteration of IDA*, and could
require many re-expansions of forgotten nodes to recreate the best path
and extend it one more node.
• RBFS is an optimal algorithm if the heuristic function h(n) is admissible.
• Its space complexity is linear in the depth of the deepest optimal solution
• The time complexity is difficult to characterize: it depends both on the
accuracy of the heuristic function and on how often the best path changes as
nodes are expanded.
Search and exploration
• Memory-bounded algorithms, called RBFS and MA*
• Both IDA* and RBFS are subject to the exponential increase in complexity
associated with searching on as they cannot check for repeated states other
than those on the current path.
• So they may explore the same state many times.
• IDA* and RBFS use too little memory.
• Between iterations, IDA* retains only a single number ie. the current f -cost limit
and RBFS retains more information in memory, but it uses only linear space:
even if more memory were available, RBFS has no way to make use of it.
• It's always better to use all available memory.
• Two algorithms that do this are MA* (memory-bounded A*) and SMA*
(simplified MA*).
Search and exploration
• Heuristic Functions:
• Heuristic is thumb rule
• Definition by Judea Pearl : Heuristics are criteria, methods or principles for
deciding which among several alternative courses of action promises to be the
most effective in order to achieve some goal
• Heuristic function is used to identify the promising search path
• Heuristic function h(n) at node n is an estimate of optimum cost from the
current node to goal
• h(n)= estimated cost of the cheapest path from node n to goal node
• Example : Path from Kolkata to Guwahati
• Heuristic for Guwahati is straight line distance between Kolkata and Guwahati
• H(Kolkata) = Euclidean distance (Kolkata, Guwahati)
Search and exploration
• Local Search Algorithms And Optimization Problems
• The previous search algorithms are designed to explore search spaces
systematically
• It keeps one or more paths in memory and record which alternatives have
been explored at each point along the path and which have not.
• When a goal is found, the path to that goal also constitutes a solution to
the problem.
• But sometimes the path to goal is not relevant what matter is the result
such as in
– 8 queens or puzzle problem,
– integrated-circuit design,
– factory-floor layout,
– job-shop scheduling
– automatic programming,
– telecommunications network optimization,
– vehicle routing,
– portfolio management
•
Search and exploration
• Local Search Algorithms And Optimization Problems
• Algorithm searches locally not globally, its greedy i.e. it moves ahead till it
gets best move else it stops and there is no backtracking
• Local search algorithms operate using a single current state (rather than
multiple paths) and move only to neighbours of that state.
• The paths followed by the search are not retained and are not systematic
1 2 4 1 2 4 1 2 4
- 5 7 5 7 - 5 6 7
3 6 8 3 6 8 3 - 8
5 5
- 2 4 1 2 4
1 5 7 3 5 7
3 6 8 - 6 8 Not saved in memory
When the heuristic 5 is present at level 2 which is greater than 4 the algo will
stop and it is local maxima
https://www.youtube.com/watch?v=rA3a8QDtYLs
Search and exploration
• Variants of hill-climbing:
• Stochastic hill climbing: it chooses at random from among the uphill
moves;
– the probability of selection can vary with the steepness of the uphill
move.
– This usually converges more slowly but at times can give better solution
• First-choice hill climbing: It implements stochastic hill climbing by
generating successors randomly until one is generated that is better than the
current state.
– This is a good strategy when a state has many (e.g., thousands) of
successors.
• The Stochastic and First Choice of hill-climbing algorithms are incomplete
and they often fail to find a goal when one exists because they can get stuck
on local maxima.
• Random-restart hill climbing : It adopts the well known statement, "If at
first you don't succeed, try, try again."
– It conducts a series of hill-climbing searches from randomly
generated initial state and stopping when a goal is found.
Search and exploration
• Local search in continuous space:
• Local search methods work on complete state formulation
• They keep only small number of nodes in the memory
• Local search algorithm is useful for solving optimization problems where
– it's often easy to find the solution
– But hard to find the best solution
• The goal of the algorithm is to find optimal configuration in limited time
• In path finding its easy to find multiple paths but specific best path is difficult
task
• In many optimization problems path is irrelevant and the goal state itself is
solution so can go for iterative method
• Local search is ideal when paths are known
• Ex.N queens problem once we have final configuration, we can get solution
how we get solution is not important
Search and exploration
• Constraint Satisfaction Problems (CSP) :
• The states and goal test conform to a standard, structured, and very simple
representation
• Search algorithms can be defined that take advantage of the structure of
states and use general-purpose rather than problem-specific heuristics to
enable the solution of large problems
• The standard representation of the goal test reveals the structure of the
problem itself .
• This leads to methods for problem decomposition and to an understanding of
the connection between the structure of a problem and the difficulty of
solving it.
• CSP is defined by a set of variables, XI, X2,. . . , Xn, and a set of
constraints, C1, C2,. . . , Cn
• Each variable Xi has a nonempty domain Di of possible values
• Each constraint Ci involves some subset of the variables and specifies the
allowable combinations of values for that subset.
• Examples of simple problems that can be modeled as a constraint satisfaction
problem are Eight queens puzzle, Map coloring problem, Sudoku,
Crosswords, etc.
Search and exploration
• Constraint Satisfaction Problems (CSP) :
• An assignment that does not violate any constraints is called a consistent or
legal assignment.
• A complete assignment is one in which every variable is mentioned, and a
solution to a CSP is a complete assignment that satisfies all the constraints.
• Some CSPs also require a solution that maximizes an objective function.
Color Map
Color Map
Constraint Graph
Flip Classroom
Constraint Satisfaction Problem : Crypt Arithmetic
Cryptarithmetic
• Crypt arithmetic is a type of mathematical game consisting of a
mathematical equation among unknown numbers, whose digits are represented by letters.
• Each letter should represent a different digit, and (as in ordinary arithmetic notation) the
leading digit of a multi-digit number must not be zero
• 19 is the max value with a carryover for two one-digit number in the same column.
• Carry over can only be 1 or 0 ( 0 or 1 as per as per vinod chandra book AI and ML
and only 1 as per Russel Norvig Book) we can go with any keeping constraints
satisfied
Basic Approach to solve Cryptarithmetic Questions:
Following mentioned points are meant to be kept in mind while solving cryptarithmetic questions:
1. Understand the Problem:
○ Carefully read the cryptarithmetic puzzle to understand the given equations and constraints.
○ Identify the letters that represent unique digits in the equation.
2. List the Letters:
○ List all the distinct letters involved in the puzzle.
○ Assign a placeholder for each letter (e.g., A, B, C, … Z) to represent digits.
3. Formulate the Equation:
○ Convert the given words into a mathematical equation.
○ Ensure that the equation follows standard mathematical rules (addition, subtraction,
multiplication, or division).
4. Identify Constraints:
○ Identify any constraints or relationships given in the puzzle. For example, if a letter cannot
be zero (0), note it down.
5. Start with the Easiest Part:
○ Look for parts of the equation that are straightforward to solve. This may involve finding
single-digit additions or subtractions.
Basic Approach to solve Cryptarithmetic Questions:
e. Continue the process of assigning digits, checking for consistency, and refining your
assignments.
f. Use logical deductions and process of elimination to narrow down possibilities.
g.
Example : Cryptarithmetic
Cryptarithmetic
T = W = O =4
T W O 7 3 {0,1,2,3,4,5,6,7,8,9}
+ T W O T = W = O =4
+ 7 3
----------------------
1 4 6 8
F O U R
7 6 5
7 6 5
+1 +1
1 5 3 0
Other Solutions :
938+938=1876 , 928+928=1856 , 867+867=1734, 846+846=1692, 836+836=1672 ,
765+765=1530 , 734+734=1468
Cryptarithmetic
C4 C3 C2 C1 C0
FORTY 29786
+ T EN + 850 1 2 1 1
+ 850
+ TEN
----- F=2 O =9 R =7 T =8 Y=6
---------------------- 31486
SIXTY T =8 E=5 N=0
T =8 E =5 N=0
Column 1: N is either 0 or 5. If N=5, then the carry to
Col2 is 1 and there is no possible value for E, so N=0. S=3 I=1 X=4 T Y=6
Column 2: E is either 0 or 5, but N=0, so E=5, and
the carry to Col3 is 1.
Column 4: I is either 0 or 1, but N=0, so I=1, O=9,
carry from Col3 is 2, and the carry to Col5 is 1.
Column 3: For 1+R+T+T >= 20, R and T must be in
{6,7,8}.
Column 5: F+1=S, so {F,S} is either {2,3} or {3,4}, so
X is not 3.
Column 3: 1+R+T+T = 22 or 24, so R is odd and
must be 7, 2T=14 or 16, T is 7 or 8, but R=7, so T=8,
X=4.
Column 5: F=2, S=3.
Column 1: Y=6.
Crypt arithmetic
•
S = 9 E=5 N =6 D =7 {0,1,2,3,4,5,6,7,8,9} ->
1. Now E+O=N O=0 E and N cannot have
same value so a carry should be generated {0,1,2,3,4,5,6,7,8,9} ->
+ M =1 O =0 R =8 E =5 from N+R {0,1,2,3,4,5,6,7,8,9} ->
+1 +1 2. E+O+1 = N i.e E+0 +1 =N {0,1,2,3,4,5,6,7,8,9}
3. E=5 N+R =5 , E+0+1 =N=6 R=9 So conflict
M =1 O=0 N =6 E =5 Y =2 as S=9
4. We can generate carry from D+E so that R=8
5. D+E = 7+5=12
1 1
9 5 6 7
+ 1 0 8 5
1 0 6 5 2
+1 +1
S E N D 9 5 6 7
1 0 8 5
+ M O R E
M O N E Y 1 0 6 5 2
Crypt arithmetic
• It is cryptography ie encryption and decryption of data being transmitted
• Suppose we have expression
– SEND + MORE = MONEY
1 1
• Assign a unique value from 0 to 9 to each character
S E N D 9 5 6 7
• S +M value can be max 9+8= 17 so
M value will be 1 so put value 1 at every + M O R E + 1 0 8 5
Location where there is 1 M O N E Y 1 0 6 5 2
• S should have such a value that adding 1 The number assignment is not
will generate borrow so it S should be 9 and unique n for every addition
borrows is required to be
O will get value zero(0), M =1 considered
• N + R should generate carry
• E + 1 = N (Eq 1) , N+R(+1) carry from =E+10 (Eq2)
• Substitute Eq 1 in Eq 2 eliminate N so E+1+R(+1) = E+10
• (+1) May or may not be considered so in eq. E will get cancelled R=9
• But 9 is already used. So consider +1 so R = 8 and there is carry from N+R
• D+E should also generate carry and 9 and 8 are now used 2 combinations 7+6 or 7+5 are
possible as we shud not get sum as 10, D=7 E=5 E+1 =N =6
Crypt arithmetic
•
{0,1,2,3,4,5,6,7,8,9} ->
1. F+F Should generate carry 5 +5 =10 {0,1,2,3,4,5,6,7,8,9} ->
FOUR {0,1,2,3,4,5,6,7,8,9} ->
+ FOUR 2. E =1, I = 0
3. O+O =G 2+2 =4 G=4 {0,1,2,3,4,5,6,7,8,9} ->
-----------------
EIG H T 4. U+U =H 3+3 =6 H=6
5. R+R =T 7+7 =14 4 is assigned to G so
cannot use {0,1,2,3,4,5,6,7,8,9} ->
6. 8+8 =16 then R=8 T =6 H=7 OR
Solution 1 {0,1,2,3,4,5,6,7,8,9}
7. 9 + 9 =18 R = 9 T =8 H =7
Solution 2
5 2 3 4
+ 5 2 3 4
E= 1 0 4 6 8
B=7 L= 9 A= 2 C=0 K=8
https://tamura70.gitlab.io/web-puzzle/cryptarithm/c/out/colors.out
Cryptarithmetic
POTATO+TOMATO=PUMPKIN
(168486+863486=1031972)
https://www.youtube.com/watch?v=HC6Y49iT
g1k
Real World CSPs
● Assignment Problems : Who teaches what class
● Timetabling Problems : Which Class is offered when and where
● Hardware Configuration
● Spreadsheets
● Transportation scheduling
● Factory Scheduling
● FloorPlanning
Search and exploration
• Backtracking search for CSP:
• The algorithm is modeled on the recursive depth-first search
• Backtracking search is used for a depth-first search that chooses values for
one variable at a time and backtracks when a variable has no legal values left
to assign.
1. Forward checking
2. Constraint propagation
Search and exploration
• Propagating information through constraints: Forward checking :
• One way to make better use of constraints during search is called forward checking.
• Whenever a variable X is assigned, the forward checking process looks at each unassigned
variable Y that is connected to X by a constraint and deletes from Y's domain any value that
is inconsistent with the value chosen for X.
• Following is the The progress of a map-coloring search with forward checking
• WA = red is assigned first; then forward checking deletes red from the domains of the
neighboring variables NT and SA. After Q = green, green is deleted from the domains of NT,
SA, and NSW. After V = blue, blue is deleted from the domains of NSW and SA, leaving SA
with no legal values.
Search and exploration
• Propagating information through constraints: Constraint Propagation:
• The forward checking detects many inconsistencies, it does not detect all of them.
• Diagram shows that when WA is red and Q is green, both NT and SA are forced to be
blue.
• But they are ,adjacent and so cannot have the same value.
• Forward checking does not detect this as an inconsistency, because it does not look
far enough ahead.
• Constraint propagation is the general term for propagating the implications of a
constraint on one variable onto other variables;
Search and exploration
• Games: Optimal decisions in games:
• In a multiagent environments, any given agent will need to consider the
actions of other agents and how they affect its own welfare.
• The unpredictability of these other agents can introduce many possible
contingencies into the agent's problem solving process
• In Competitive multiagent environments the agents' goals are in conflict,
give rise to adversarial search problems known as games.
• Mathematical game theory, a branch of economics, views any multiagent
environment as a game provided that the impact of each agent on the others is
"significant," regardless of whether the agents are cooperative or competitive
• In AI games are specialized kind-what game theorists call deterministic,
turn-taking, two-player, zero-sum games of perfect information.
• This means deterministic, fully observable environment in which there are
two agents whose actions must alternate and in which the utility values at the
end of the game are always equal and opposite
Search and exploration
• For example, if one player wins a game of chess (+1), the other player
necessarily loses (-1).
• It is this opposition between the agents' utility functions that makes the
situation adversarial ( opposition/conflict)
• Games have engaged the intellectual faculties of humans to an alarming
degree-for as long as civilization has existed.
• For AI researchers, the abstract nature of games makes them an appealing
subject for study.
• The state of a game is easy to represent, and agents are usually restricted
to a small number of actions whose outcomes are defined by precise rules
Search and exploration
• Trees are used in game playing, in particular for the problems of searching
game trees.
• The games are classified into three groups:
• Single-player pathfinding problems.
– Rubik’s Cube
– Sliding puzzle.
– Travelling Salesman Problem.
• Two-player games.
– Chess
– Checkers
– Othello
• Constraint satisfaction problems.
– Eight Queens
– Sudoku
•
Search and exploration
• Each game consists of a problem space, an initial state, and a single (or a set
of) goal states.
• A problem space is a mathematical abstraction in a form of a tree:
– the root represents current state
– nodes represent states of the game
– edges represent moves
– leaves represent final states (win, loss or draw)
• Mini-Max Algorithm:
• Zero Sum games: Games with two players in which one person's gains are
the result of another person's losses are called zero-sum games
• Minimax is a kind of backtracking algorithm that is used in decision making and game
theory to find the optimal move for a player, assuming that your opponent also plays
optimally.
• It is widely used in two player turn-based games such as Tic-Tac-Toe, Backgammon,
Chess, etc.
• In Minimax the two players are called maximizer and minimizer.
• The maximizer tries to get the highest score possible while the minimizer tries to do
the opposite and get the lowest score possible.
• Every board state has a value associated with it.
• In a given state if the maximizer has upper hand then, the score of the board will tend
to be some positive value.
• If the minimizer has the upper hand in that board state then it will tend to be some
negative value.
• The values of the board are calculated by some heuristics which are unique for every
type of game.
Search and exploration
• Consider a game which has 4 final states and paths to reach final state are
from root to 4 leaves of a perfect binary tree
• Assume you are the maximizing player and you get the first chance to move,
i.e., you are at the root and your opponent at next level.
•Maximizer goes LEFT: It is now the minimizers turn. The minimizer now has a
choice between 3 and 5. Being the minimizer it will definitely choose the least among
both, that is 3
•Maximizer goes RIGHT: It is now the minimizers turn. The minimizer now has a
choice between 2 and 9. He will choose 2 as it is the least among the two values.
Search and exploration
• Being the maximizer you would choose the larger value that is 3.
• Hence the optimal move for the maximizer is to go LEFT and the optimal value
is 3.
• The minimax algorithm explores the entire game tree using a depth-first
search.
• At each node in the tree where A-player has to move, A-player would like to
play the move that maximizes the payoff.
• Thus, A-player will assign the maximum score amongst the children to the
node where Max makes a move.
• Similarly, B-player will minimize the payoff to A-player.
• The maximum and minimum scores are taken at alternating levels of the
tree, since A and B alternate turns.
The minimax algorithm computes the minimax decision for the leaves of the
game tree and than backs up through the tree to give the final value to the
current state.
Example tic-tac-toe game : From the initial state, MAX has nine possible moves.
Play alternates between MAX'S placing an x and MIN'S placing an o until we reach leaf nodes
corresponding to terminal states such that one player has three in a row or all the squares are filled.
The number on each leaf node indicates the utility value of the terminal state from the point of view of
MAX;
high values are assumed to be good for MAX and bad for MIN (which is how the players get their
names).
It is MAX'S job to use the search tree (particularly the utility of terminal states) to determine the best
move.
Search and exploration
15
16
Search and exploration
MAX
Back up Min
No Point in exploring
this branch
20
Back up Max 25
Alpha Beta Pruning
B B
Stages in the calculation of the optimal decision for the game tree
At each point, the range of possible values for each node is shown.
(a) The first leaf below B has the value 3. Hence, B, which is a MIN node,
has a value of at most 3.
(b) The second leaf below B has a value of 12; MIN would avoid this
move, so the value of B is still at most 3.
A A
B B
C
(c) The third leaf below B has a value of 8; we have seen all B's successors, so the
value of B is exactly 3. Now, we can infer that the value of the root is at least 3,
because MAX has a choice worth 3 at the root.
(d) The first leaf below C has the value 2. Hence, C, which is a MIN node, has a
value of at most 2. But we know that B is worth 3, so MAX would never choose C.
Therefore, there is no point in looking at the other successors of C. So we prune
those 2 branches of C
This is an example of alpha-beta pruning.
A A
B B
C C
D D
(e) The first leaf below D has the value 14, so D is worth at most 14. This is still
higher than MAX'S best alternative (i.e., 3), so we need to keep exploring
D's successors. Notice also that we now have bounds on all of the successors of
the root, so the root's value is also at most 14.
(f) The second successor of D is worth 5, so again we need to keep exploring.
The third successor is worth 2, so now D is worth exactly 2. MAX'S decision at
the root is to move to B, giving a value of 3.
LEVEL 1
Max =α β =+∞
α = -∞
β =+∞ LEVEL 2
β =+∞
Min Min α = -∞
α = -∞
=β
β =+∞ β =+∞ β =+∞
β =+∞
α = -∞ α = -∞ α = -∞
α = -∞
β =+∞
α = -∞
10 5 7 11 12 8 9 8 5 12 11 12 9 8 7 10
β =+∞
β =+∞->7 LEVEL 2
Min Min α = -∞
α = -∞
=β
β =+∞->7 β =+∞ β =+∞
β =+∞ α = -∞ α = -∞
α = -∞
α = -∞->5->7
10 5 7 11 12 8 9 8 5 12 11 12 9 8 7 10
β =+∞ LEVEL 2
β =+∞->7
Min Min α = -∞
α = -∞
=β
β =+∞->7 β =+∞ β =+∞
β =+∞ α = -∞ α = -∞
α = -∞
α = -∞->5->7
10 5 7 11 12 8 9 8 5 12 11 12 9 8 7 10
β =+∞ LEVEL 2
β =+∞->7
Min Min α = -∞
α = -∞
=β
β =7 β =+∞ β =+∞
β =+∞ α = -∞ -> 7 α = -∞
α = -∞
α = -∞->5->7
β =7
β =+∞ -> β =+∞ ->7
α = -∞
10->5 α =5
α = -∞
Min Min Min Min Min Min Min Min LEVEL 4
10 5 7 11 12 8 9 8 5 12 11 12 9 8 7 10
β =+∞ LEVEL 2
β =+∞->7
Min Min α =7
α = -∞
=β
β =+∞ β =+∞
β =+∞ β =7 α = -∞
α = -∞ -> 7 α =7
α = -∞->5->7
β =7 β =+∞->5
β =+∞ -> β =+∞ ->7
α = -∞ α =7
10->5 α =5
α = -∞
Min Min Min Min Min Min Min Min LEVEL 4
10 5 7 11 12 8 9 8 5 12 11 12 9 8 7 10
Level 1: Max: α = -∞, β =+∞ will be compared α = -∞, β =7 at level2 and the value of
α =7 and will propagate to the next level 2,3 and 4
Level 4: Min: α = 7, β = +∞ compared 5 and β = 5 alpha >=Beta so prune the branch 12
Level 3 : β =+∞ α = 7 no change
LEVEL 1
Max =α β =+∞
α = -∞->7
β =+∞ β =11
β =+∞ β =7 α =7
α = -∞ -> 7 α = 7->11
α = -∞->5->7 LEVEL 3
β =7 β =+∞->5
β =+∞ -> β =+∞ ->7 β =+∞->11
α = -∞ α =7
10->5 α =5 α =7
α = -∞
Min Min Min Min Min Min Min Min LEVEL 4
10 5 7 11 12 8 9 8 5 12 11 12 9 8 7 10
β =7 β =+∞ β =11
β =+∞
α = -∞ -> 7 α = 7->11 α = 7->8 LEVEL 3
α = -∞->5->7
β =7 β =+∞->5 β =11->7
β =+∞ -> β =+∞ ->7 β =11 ->9->8 α =8
α = -∞ α =7 β =+∞->11
10->5 α =5 α =7
α =7
α = -∞
Min Min Min Min Min Min Min Min LEVEL 4
10 5 7 11 12 8 9 8 5 12 11 12 9 8 7 10
β =7 β =+∞ β =11
β =+∞
α = -∞ -> 7 α = 7->11 α = 7->8 LEVEL 3
α = -∞->5->7
β =7 β =+∞->5 β =11->7
β =+∞ -> β =+∞ ->7 β =11 ->9->8 α =8
α = -∞ α =7 β =+∞->11
10->5 α =5 α =7
α =7
α = -∞
Min Min Min Min Min Min Min Min LEVEL 4
10 5 7 11 12 8 9 8 5 12 11 12 9 8 7 10
β =7 β =+∞ β =11
β =+∞
α = -∞ -> 7 α = 7->11 α = 7->8 LEVEL 3
α = -∞->5->7
β =7 β =+∞->5 β =11->7
β =+∞ -> β =+∞ ->7 β =11 ->9->8 α =8
α = -∞ α =7 β =+∞->11
10->5 α =5 α =7
α =7
α = -∞
Min Min Min Min Min Min Min Min LEVEL 4
10 5 7 11 12 8 9 8 5 12 11 12 9 8 7 10
Nodes in memory using Mini-max : 15 min max nodes with 16 terminal nodes
Nodes in memory using Alpha Beta Pruning : 14 min max nodes and terminal
nodes 12 Saving of space Number of Alpha cut off = 01, Beta cutoff =02
http://people.cs.pitt.edu/~litman/cou
rses/cs2710/lectures/pruningRevie
w.pdf