Unit 3
Unit 3
Structure Page No
3.0 Introduction
3.1 Objectives
3.2 Formulating search in state space
3.2.1 Evaluation of search Algorithm
3.3Uninformed Search
3.3.1 Breath-First search (BFS)
3.3.2 Time and space complexity of BFS
3.3.3 Advantages & disadvantages of BFS
3.3.4 Depth First search (DFS)
3.3.5 Performance of DFS algorithm
3.3.6 Advantages and disadvantages of DFS
3.3.7 Comparison of BFS and DFS
3.4 Iterative Deepening Depth First search (IDDFS)
3.4.1 Time and space complexity of IDDFS
3.4.2 Advantages and Disadvantages of IDDFS
3.5 Bidirectional search
3.6 Comparison of Uninformed search strategies
3.7 Informed (heuristic) search
3.7.1 Strategies for providing heuristics information
3.7.2 Formulation of Informed (heuristic) search problem as state space
3.7.3 Best-First search
3.7.4 Greedy Best first search
3.8 A* Algorithm
3.8.1 Working of A* algorithm
3.8.2 Advantages and disadvantages of A* algorithm
3.8.3 Admissibility properties of A* algorithm
3.8.4 Properties of heuristic algorithm
3.8.5 Results on A* algorithm
3.9 Problem reduction search
3.9.1 Problem definition in AND-OR graph
3.9.2 AO* algorithm
3.9.3 Advantages of AO* algorithm
3.10 Memory Bound heuristic search
3.10.1 Iterative Deepening A* (IDA*)
3.10.2 Working of IDA*
3.10.3 Analysis of IDA*
3.10.4 Comparison of A* and IDA* algorithm
3.11 Recursive Best First search (RBFS)
3.11.1 Advantages and disadvantages of RBFS
3.12 Summary
3.13 Solutions/Answers
3.14 Further readings
3.0 INTRODUCTION
Before an AI problem can be solved it must be represented as a state space. In AI, a wide range
of problems can be formulated as search problem. The process of searching means a sequence of
action that take you from an initial state to a goal state as sown in the following figure 1.
In the unit 2 we have already examined the concept of a state space and adversarial (game
playing) search strategy. In many applications there might be multiple agents or persons
searching for solutions in the same solution space. In adversarial search, we need a path to take
action towards the winning direction and for finding a path we need different type of search
algorithms.
Search algorithms are one of the most important areas of Artificial Intelligence. This unit will
explain all about the search algorithms in AI which explore the search space to find a solution.
One disadvantage of state space representation is that it is not possible to visualize all states for
a given problem. Also, the resources of the computer system are limited to handle huge state
space representation. But many problems in AI take the form of state-space search.
The states might be legal board configurations in a game, towns and cities in some sort of
route map, collections of mathematical propositions, etc.
The state-space is the configuration of the possible states and how they connect to each other
e.g., the legal moves between states.
When we don't have an algorithm which tells us definitively how to negotiate the state-space
we need to search the state-space to find an optimal path from a start slate to a goal state,
We can only decide what to do (or where to go), by considering the possible moves from the
current state, and trying to look ahead as far as possible. Chess, for example is a very difficult
state space search problem.
Searching is the process looking for the solution of a problem through a set of possibilities (state
space).In general, the searching process starts from the initial state (root node ) and proceeds by
performing the following steps:
Check whether the current state is the goal state or not?
Expand the current state to generate the new sets of states.
Choose one of the new states generated for search depending upon search strategy
(for example BFS, DFS etc.).
Repeat step 1 to 3 until the goal state is reached or there are no more state tube
expanded.
Evaluation (properties) of search strategies : A search strategy is characterized by the
sequence in which nodes are expanded. Any search algorithms are commonly evaluated
according to the following four criteria. The following four essential properties of search
algorithms is used to compare the efficiency of any search algorithms.
Completeness: A search algorithm is said to be complete if it guarantees to return a solution, if
exist.
Optimality/Admissibility: If a solution found for an algorithm is guaranteed to be the best
solution (lowest path cost) among all other solutions, then such a solution for is said to be an
optimal solution.
Time Complexity: Time complexity is a measure of time for an algorithm to complete its task.
Usually measured in terms of the number of nodes expended during the search.
Space Complexity: It is the maximum storage space required at any point during the search.
Usually measured in terms of the maximum number of nodes in memory at a time.
Time and space complexity are measured in terms of:
b - max branching factor of the search tree
d - depth of the least-cost solution
m - max depth of the search tree (may be infinity)
In all search algorithms, the order in which nodes are expended distinguishes them from one
another. There are two broad classes of search methods:
Search Algorithm
Uniformed/Blind
Uninformed search is also called Brute force search or Blind search or Exhaustive search. It is
called blind search because of the way in which search tree is searched without using any
information about the search space. It is called Brute force because it assumes no additional
knowledge other than how to traverse the search tree and how to identify the leaf nodes and goal
nodes. This search ultimately examines every node in the tree until it finds a goal.
Informed search is also called as Heuristic (or guided) search. These are the search techniques
where additional information about the problem is provided in order to guide the search in a
specific direction. A heuristic is a method that might not always find the best solution but is
guaranteed to find a good solution in reasonable time. By sacrificing completeness, it increases
efficiency.
The following table summarizes the differences between uninformed and informed search:
3.1 OBJECTIVES
After studying this unit, you should be able to:
Differentiate the Uninformed and informed search algorithm
Formulate the search problem in the form of state space
Explain the differences between various uninformed search approaches such as BFS,
DFS, IDDFS, Bi-directional search.
Evaluate the various Uninformed search algorithm with respect to Time, space and
Optimality/Admissibility criteria.
Explain Informed search such as Best-First search and A* algorithm.
Differentiate between advantages and disadvantages of heuristic search: A* and AO*
algorithm
Differentiate between memory bound search: Iterative Deepening A* and Recursive
Best-First Search.
A state space is a graph, (V, E) where V is a set of nodes and E is a set of arcs, where each arc is
directed from one node to another node.
V: a node is a data structure that contains state description, plus, optionally other
information related to the parent of the node, operation to generate the node from that
parent, and other bookkeeping data.
E: Each arc corresponds to an applicable action/operation. The source and destination
nodes are called as parent (immediate predecessor) and child (immediate successor)
nodes with respect to each other. Ancestors(also called predecessors) and descendants
(also called successors) node. Each arc has a fixed, non-negative cost associated with it,
corresponding to the cost of the action.
Each node has a set of successor nodes. Corresponding to all operators (actions) that can apply at
source node’s state. Expanding a node is generating successor nodes and adding them (and
associated arcs) to the state-space graph. One or more nodes may be designated as start nodes.
A goal test predicate is applied to a node to determine if its associated state is a goal state. A
solution is a sequence of operations that is associated with a path in a state space from a start
node to a goal node. Thecost of a solution is the sum of the arc costs on the solution path.
State-space search is the process of searching through a state space for a solution by making
explicit a sufficient portion of an implicit state-space graph to include a goal node.
Hence, initially V={S}, where S is the start node; when S is expanded, its successors are
generated, and those nodes are added to V and the associated arcs are added to E. This process
continues until a goal node is generated (included in V) and identified (by goal test).
To implement any Uninformed search algorithm, we always initialize and maintain a list called
OPEN and put start node of G in OPEN. If after some time, we find OPEN is empty and we are
not getting “goal node”, then terminate with failure. We select a node 𝒏 from OPEN and if
𝒏 ∈ 𝑮𝒐𝒂𝒍 𝒏𝒐𝒅𝒆 , then terminate with success, else we generate the successor of n (using
operator O) and insert them in OPEN. In this way we repeat the process till search is successful
or unsuccessful.
Search strategies differ mainly on how to select an OPEN node for expansion at each step of
search.
A general search algorithm
1. Initialize: Set = {𝑠} , where s is a start state.
2.Fail:If 𝑂𝑃𝐸𝑁 = { }, terminate with failure.
3. Select: Select a state, n, from OPEN
4.Terminate: If 𝑛 ∈ 𝐺𝑜𝑎𝑙 𝑛𝑜𝑑𝑒, terminate with success
5. Expand: Generate the successor of n using operator O and insert them in OPEN.
6. LOOP:Goto Step 2
But the problem with the above search algorithm, it is not mentioned that when a node is already
visited, then do not revisit that node again. That is “how we can maintain a part of the state
space that is already visited”. So, we have an extension of the same algorithm, where we can
save the explicit state space. To save the explicit space, we maintained another list called
CLOSED.
Thus, to implement any Uninformed search algorithm efficiently, two list OPEN and CLOSED
are used.
Now we can select a node from OPEN and save it in CLOSED. The CLOSED list keeps record
of nodes that are Opened. The major difference of this algorithm with the previous algorithm is
that when we generate successor node from CLOSED, we check whether it is already in
(𝑂𝑃𝐸𝑁 ∪ 𝐶𝐿𝑂𝑆𝐸𝐷). If it is already in (𝑂𝑃𝐸𝑁 ∪ 𝐶𝐿𝑂𝑆𝐸𝐷), we will not insert in OPEN again,
otherwise insert. The following modified algorithm is used to save the explicit space using the
list CLOSED.
Note that initially OPEN list initializes with start state of G (e.g.,𝑶𝑷𝑬𝑵 = {𝒔}) and CLOSED list as
empty (e.g.,𝑪𝑳𝑶𝑺𝑬𝑫 = {}).
In any search algorithm, we select a node and generate its successor. Search strategies differ
mainly on how to select an OPEN node for expansion at each step of search. Also, Insertion or
deletion of any node from OPEN list depends on specific search strategy. Any search algorithms
are commonly evaluated according to the following 4 criteria:It is the measure to evaluate the
performance of the search algorithms:
Time Complexity: How long (worst or average case) does it take to find a solution?
Usually measured in terms of the number of nodes expanded.
Space Complexity: How much space is used by the algorithm? Usually measured in
terms of the maximum size that the “OPEN" list becomes during the search. The Time
and Space complexity are measured in terms of: The branching factor or maximum
number of successors of any node and d: the depth of shallowest goal node (depth of the
least cost solution) and m: The maximum depth (length) of any path in the state space
(may be infinite).
Search process constructs a search tree, where root is the initial state S, and leaf nodes are
nodesnot yet been expanded (i.e., they are in OPEN List) or having no successors (i.e.,
they're dead ends"). Search tree may be infinite because of loops even if statespace is small
Search strategies mainly differ on select OPEN. Each node represents a partial solution path
and cost of the partial solution path) from the start node to the given node. In general, from
this node there are many possible paths (and therefore solutions that have this partial path as
a prefix.
All search algorithms are distinguished by the order in which nodes are expended. There are
two broad classes of search methods: Uninformed search and Heuristic Search. Let us first
discuss the Uninformed search.
Breadth-first search
Depth-first search
Uniform cost search
Iterative deepening depth-first search
Bidirectional Search
It is the simplest form of blind search. In this technique the root node is expanded first, then all its
successors are expanded and then their successors and so on. In general, in BFS, all nodes are
expanded at a given depth in the search tree before any nodes at the next level are expanded. It
means that all immediate children of nodes are explored before any of the children’s children are
considered. The search tree generated by BFS is shown below in Fig 2.
Root
A B C
D E F G
Goal Node
Fig 2 Search tree for BFS
Note that BFS is a brute-search, so it generates all the nodes tor identifying the goal and note that
we are using the convention that the alternatives are tried in the left-to-right order.
A BFS algorithm uses a data structure-queue that works on FIFO principle. This queue will hold
all generated but still unexplored nodes. Please remember that the order in which nodes are
placed on the queue or removal and exploration determines the type of search.
We can implement it by using two lists called OPEN and CLOSED. The OPEN list contains
those states that are to be expanded and CLOSED list keeps track of state already expanded.
Here OPEN list is used as a queue.
BFS is effective when the search tree has a low branching factor.
Example1: Consider the following graph in fig-1 and its corresponding state space tree
representation in fig-2. Note that A is a start state and G is a Goal state.
E A
B
B C
A D E H
C
D E D G
C C F B F
G
G G H E G H
Step1: Initially open contains only one node Step 5: Node D is removed from open. Its children C and F are
corresponding to the source state A. generated and added to the back of open.
A A
B C B C
C
D E D G C
D E D G
C F B F C F B F
G G H E G H G G H E G H
B C
B C
C
D E D G
C
D E D G
C F B F C F B F
G G H E G H G G H E G H
Open= B,C CLOSED={A } Open= D,G,C,F CLOSED=A,B,C,D,E
Step: 3: Node B is removed from open and is Step 7: D is expanded, B and F are put in OPEN.
expended. Its children D, E are generated and put at the
A
back of open.
A
B C
B C
C
D E D G
C
D E D G
C F B F
C F B F
G G H E G H
G G H E G H
Open= G,C,F,B,F
Open= C,D,E CLOSED=A,B,C,D,E,D
CLOSED={A,B}
Step 4: Node C is removed from open and is expanded Step 8: G is selected for expansion. It is found to be a goal
its children D and G are added to the back of open. node. So, the algorithm returns the path ACG by following the
parent pointers of the node corresponding to G. The algorithm
A
A
B C
B C
C
D E D G
C
D E D G Goal!
C F B F
C F B F
G G H E G H
G G H E G H
Open=D,E,D,G terminates.
CLOSED={A,B,C}
Open=C,F,B,F
CLOSED={A,B,C,D,E.G}
1 b
2 b^2
d b^d
Fig 3Search tree with b branching factor
For Example, consider a complete search tree of depth 12, where every node at depths
0,1, . . . , 11 has 10 children (branching factor b=10) and every node at depth 12 has 0 children,
then there are
1. (10 − 1)
1 + 10 + 10 + 10 + ⋯ + 10 =
10 − 1
= = 𝑂(10 ) nodes in the complete search tree.
• BFS is suitable for problems with shallow solutions
Space complexity:
BFS has to remember each and every node it has generated. Space complexity (maximum length
of OPEN list):
So, space complexity is given by:
1+b+b2+b3+…bd= O(bd).
Performance of BFS:
Time Required for BFS for tree of b branching factor and d depth is 𝑂(𝑏 ).
Space (memory) requirement for a tree with b branching factor and d depth is also 𝑂(𝑏 )
BFS algorithm is Complete (if b is finite).
BFS algorithm is Optimal (if cost = 1 per step)
Disadvantages: BFS has certain disadvantages also. They are given below-
1. Time complexity and Space complexity are both O(bd) i.e., exponential type. This is very
hurdle.
2. All nodes are to be generated in BFS. So, even unwanted nodes are to be remembered (stored
in queue) which is of no practical use of the search.
In depth-first search we go as far down as possible into the search tree/graph before backing up
and trying alternatives. It works by always generating a descendent of the most recently
expanded node until some depth cut off is reached and then backtracks to next most recently
expanded node and generates one of its descendants. So only path of nodes from the initial node
to the current node is stored, in order to execute the algorithm. For example, consider the following
tree and see how the nodes are expended using DFS algorithm.
Example1:
S (Root)
A B
c D E F
(Goal Node)
Fig. 5 Search tree for DFS
After searching root node S, then A and C, the search backtracks and tries another path from
A. Nodes are explored in the order 𝑆, 𝐴, 𝐶, 𝐷, 𝐵, 𝐸, 𝐹.
Here again we use the list OPEN as a STACK to implement DFS. If we found that the first
element of OPEN is the Goal state, then the search terminates successfully.
6. LOOP:Goto Step 2
Note: The only difference between BFS and DFS is in Expend (step 5). In BFS, we always insert the
generated successors at the right end of OPEN list, whereas in DFS at the left end of OPEN list.
Time Required for DFS for tree of b branching factor and m depth (of shallowest goal
node) is 𝑂(𝑏 ).
Space (memory) requirement for a tree with b branching factor and m depth (of
shallowest goal node) is also 𝑂(𝑏𝑚)
Advantages:
If depth-first search finds solution without exploring much in a path then the time and
space it takes will be very less.
The advantage of depth-first Search is that memory requirement is only linear with
respect to the search graph. This is in contrast with breadth-first search which requires
more space.
Example1: Consider the following graph in fig-1 and its corresponding state space tree
representation in fig-2. Note that A is a start state and G is a Goal state.
B C
E
B
C
D E D G
A D E H
C F B F
G G G H E G H
A
A
B C
B C
C
D E D G
C
D E D G
C F B F
C F B F
G G H E G H
G G H E G H
Step 2: A is removed from open. The node A is Step 5: Node C is removed from open. Its children G and
expanded, and its children B and C are generated. They F is added to the front of open.
are placed at the from of open.
A A
B C B C
C
D E D G C
D E D G
C F B F C F B F
G G H E G H G G H E G H
Step 3: Node B is removed from open and is expended. Step 6: Node G is expanded and found to be a goal node.
Its children D, E are generated and put at the front open. The solution path A-B-D-C-G is returned and the
algorithm terminates.
A A
B C B C
C
D E D G C
D E D G
C F B F C F B F
G G H E G H G G H E G H
BFS goes level wise , but requires more space as compared to DFS. The space required by DFS is O(d)
d
where d is depth of tree, but space required by BFS is O(b ).
DFS: The problem with this appraoch is, if there is a node close to root, but not in first few subtrees
explored bt DFS, then DFS reaches that node very late. Also, DFS may not find shortest path to a node (in
terms of number of edges.)
0 node to be searched
Path followed by a
DFS
1 2
3 4 5 6
DFS: The problem with this approach is, if there is a node close to root, but not in first few subtrees
explored by DFS, then DFS reaches that node very late. Also, DFS may not find shortest path to a node
(in terms of number of edges).
Suppose, we want to find node- ‘2’ of the given infinite undirected graph/tree. A DFS starting from node-
0 will dive left, towards node 1 and so on.
An Iteratie Deepenign Depth First Search overcomes this andquickly find the required node.
Iterative Deepening Depth First Search (IDDFS) neither suffers the drawbacks of BFS nor DFS
on trees. It takes the advantages of both the strategy.
It begins by performing DFS to a depth of zero, then depth of one, depth of two, and so on until a solution
is found or some maximum depth is reached.
It is like BFS in that it explores a complete layer of new nodes at each iteration before going to next layer.
It is likes DFS for a single iteration.
It is preferred when there is a large search space, and the depth of a solution is notknown. But it performs
the wasted computation before reaching the goal depth. Since IDDFS expends all nodes at a given depth
before expending any nides at greater depth, it is guaranteed to find a shortest-length (path) solution from
initial state to goal state.
At any given time, it is performing a DFS and never searches deeper than depth ‘d’. Hence, it uses same
space as DFS.
Disadvantage of IDDFS is that it performs wasted computation prior to reaching the goal depth.
Algorithm (IDDFS)
𝐼𝑛𝑖𝑡𝑖𝑎𝑙𝑖𝑧𝑒𝑑 𝑑 = 1/∗ depth of search tree ∗/, found = false
𝑊ℎ𝑖𝑙𝑒 (𝐹𝑜𝑢𝑛𝑑 = 𝐹𝑎𝑙𝑠𝑒)
𝐷𝑂{
𝑝𝑒𝑟𝑓𝑜𝑟𝑚 𝑎 𝑑𝑒𝑝𝑡ℎ 𝑓𝑖𝑟𝑠𝑡 𝑠𝑒𝑎𝑟𝑐ℎ 𝑓𝑟𝑜𝑚 𝑠𝑡𝑎𝑟𝑡 𝑡𝑜 𝑑𝑒𝑝𝑡ℎ 𝑑.
𝑖𝑓 𝑔𝑜𝑎𝑙 𝑠𝑡𝑎𝑡𝑒 𝑖𝑠 𝑜𝑏𝑡𝑎𝑖𝑛𝑒𝑑
𝑡ℎ𝑒𝑛 𝐹𝑜𝑢𝑛𝑑 = 𝑡𝑟𝑢𝑒
𝑒𝑙𝑠𝑒
B C
D E F
G
H I J K L M N O
The Iterative deepening search proceeds as follows:
Iterative Deepening search 𝑳 = 𝟎
A
Limit = 0
A A A
B C B C C
Limit = 1
A A
A A
B C B C B C B C
D E F G D E F G D E F G E F G
Limit = 2
A
A A
C
C C
F G F G G
A A A A
B C B C B C B C
D E F G D E F G D E F G D E F G
H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O
Limit =3
A A A A A
B C B C B C B C B C
D E F G E F G E F G E F G F G
I J K L M N O J K L M N O J K L M N O K L M N O L M N O
A A A
C B C B C
F G F G F G
L M N O L M N O M N O
3.4.1 Time and space complexities of IDDFS
The time and space complexities of IDDFSalgorithm is O(b d) and O(d) respectively.
It can be shown that depth first iterative deepening is asymptotically optimal, among brute
force tree searches, in terms of time, space and length of the solution. In fact, it is linear in its
space complexity like DFS, and is asymptotically optimal to BFS in terms of the number of
nodes expanded.
Please note that in general iterative deepening is preferred uninformed search method
when there is large search space, and the depth of the solution is unknown. Also note that
iterative deepening search is analogous to BFS in that is explores a complete layer going to
the next layer.
Advantages:
1. It combines the benefits of BFS and DFS search algorithms in terms of fast search and
memory efficiency.
2. It is guaranteed to find a shortest path solution.
3. It is a preferred uniformed search method when the search space is large and the depth of
the solution is not known.
Disadvantages
1. The main drawback of IDDFS is that it repeats all the work from the previous phase. That
is, it performs wasted computations before reaching the goal depth.
d
2. The time complexity is O(b ) i.e., exponential type only.
This search is used when a problem has a single goal state that is given explicitly and all the
node generation operators have inverses,
So, it is used to find shortest path from an initial node to goal node
instead of goal itself along with path.
It works by searching forward from the initial node and backward from the goal node
simultaneously, by hoping that two searches meet in the middle.
Check at each stage if the nodes of one have been generated by the other, i.e., they meet in
the middle.
If so, the path concatenation is the solution.
Thus, the BS Algorithm is applicable when generating predecessors is easy in both forward and
backward directions and there exist only 1 or fewer goal states. The following figure illustrate
how the Bidirectional search is executed.
Root node
1 Bidirectional
13
4 Search 11
2 14
8 9 10
3 15
6 Intersection 12
Node
5 16
Goal node
Fig 7 Bidirectional search
We have node 1 as the start/root node and node 16 as the goal node. The algorithm divides the
search tree into two sub-trees. So, from start node 1, we do a forward search and at the same
time, we do a backward search from goal node 16. The forward search traverse’s nodes 1, 4, 8,
and 9 whereas the backward search traverses through nodes 16, 12, 10, and 9. We see that both
forward and backward search meets at node 9 called the intersection node. So, the total path
traced by forwarding search and the path traced by backward search is the optimal solution. This
is how the BS Algorithm is implemented.
Advantages:
Since BS uses various techniques like DFS, BFS, Depth limited search (DLS) etc, it is
efficient and requires less memory.
Disadvantages:
Implementation of the bidirectional search tree is difficult.
In bidirectional search, one should know the goal state in advance.
Practically inefficient due to additional overhead to perform insertion operation at each
point of search.
Time complexity:
⁄
The total number of nodes expended in Bidirectional search is= 2𝑏 = 𝑶 𝒃𝒅⁄𝟐 , where b is a
branching factor and d is the depth of the shallowest goal node.
d/2
Complete? Yes
Time Complexity: O(bd/2)
Space complexity: O(bd/2)
Optimal: Yes (if step cost is uniform in both forward and backward directions)
3.6 Comparison of Uninformed search strategies
The following table-1compare the efficiency of uninformed search algorithms. These are the
measure to evaluate the performance of the search algorithms:
2 3 4
6 5 7
9 8
Goal State
C D
B
E F G H I J
K L M N O P Q R
S T U
E
B
A D F H
C
G
Let A be the state and G be the final or goal state to be searched.
Q.4 Compare the Uninformed search algorithm with respect to Time, space, Optimal and
Complete.
Deciding which node to expand next, instead of doing the expansion in a strictly breadth-
first or depth-first order;
In the course of expanding a node, deciding which successor or successors to generate,
instead of blindly generating all possible successors at one time:
Deciding that certain nodes should be discarded, or pruned, from the search space.
Informed search algorithms use domain knowledge. In an informed
search, problem information is available which can guide the search. Informed search strategies
can find a solution more efficiently thanan uninformed search strategy. Informed search is also
called a Heuristic search.
Heuristics is a guess work, or additional information about the problem. It may miss the solution,
if wrong heuristics is supplied. However, in almost all problems with correct heuristic
information, it provides good solution in reasonable time
Informed search can solve much complex problem which could not be solved in another way.
We have the following informed search algorithm:
1. Best-First Search
2. A* algorithm
3. Iterative Deepening A*
The informed search algorithm is more useful for large search space. All the informed search
algorithm uses the idea of heuristic, so it is also called Heuristic search.
“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:
It takes the current state of the agent as its input and produces the estimation of how close
agent is from the goal.
Heuristic function estimates how close a state is to the goal. It is represented byh(n), and it
calculates the cost of an optimal path between the pair of states.
The heuristic method, however, might not always give the best solution, but it guaranteed to
find a good solution in reasonable time.
Informed Search Define a heuristic function. h(n). that estimates the “goodness" of a node n.
The heuristic function is an estimate, based on domain-specific information that is
computable from the current state description of how close we are to a goal.
Specifically, h(n) = estimated cost (or distance) of minimal cost path from state ‘n’ to a goal
state.
A heuristic function at a node n is an estimate of the optimum cost from the current node toa goal.
Denoted by h(n)
h(n) = estimated cost of the cheapest path from node n to a goal node
For example, suppose you want to find a shortest path from Kolkata to Guwahati, then heuristic for
Guwahati may be straight-line distance between Kolkata and Guwahati, that is
Initial state
actions
Goal State
We need to find a sequence of actions which transform the agent from the initial sate 𝑠 to Goal
state G. State space is commonly defined as a directed graph or as a tree in which each node is a
state and each arc represents the application of an operator transforming a state to a successor
state.
Thus, the problem is solved by using the rules (operators), in combination with an appropriate
control strategy, to move through the problem space until a path from initial state to a goal state
is found. This process is known as search. A solution path is a path in state space from 𝑠 (initial
sate) to G (Goal state).
We have already seen an OPEN list is used to implement an uninformed (Blind) search (section
3.2). But the problem with using only one list OPEN is that, it is not possible to keep track of the
node which is already visited. That is “how we can maintain a part of the state space that is
already visited”. To save the explicit space, we maintained another list called CLOSED. Now
we can select a node from OPEN and save it in CLOSED. Now, when we generate successor
node from CLOSED, we check whether it is already in (𝑂𝑃𝐸𝑁 ∪ 𝐶𝐿𝑂𝑆𝐸𝐷). If it is already in
(𝑂𝑃𝐸𝑁 ∪ 𝐶𝐿𝑂𝑆𝐸𝐷), we will not insert in OPEN again, otherwise insert.
Best first search uses an evaluation function f(n) that gives an indication of which node to
expand next for each node. Every node in a search space has an evaluation function (heuristic
function) associated with it. A heuristic function value h(n) on each node indicates how the node
is from the goal node. Note that Evaluation function=heuristic cost function (in case of minimization
problem) OR objective function(in case of maximization).Decision of which node to be expanded
depends onvalue of evaluation function. Evaluation value= cost/distance of current node from goal node
and for goal node evaluation function value=0
Based on the evaluation function, f(n), Best-first search can be categorized into the following
categories:
1) Greedy Best first search
2) A* search
The following 2 list (OPEN and CLOSED) are maintained to implement these two algorithms.
1. OPEN – all those nodes that have been generated & have has heuristic function applied
to them but have not yet been examined.
2. CLOSED- contains all nodes that have already been examined.
Greedy best-first search algorithm always selects the path which appears best at that moment.
It is the combination of depth-first search and breadth-first search algorithms. It uses the
heuristic function and search. Best-first search allows us to take the advantages of both
algorithms. With the help of best-first search, at each step, we can choose the most promising
node. In the best first search algorithm, we expand the node which is closest to the goal node and
the closest cost is estimated by heuristic function, i.e.
f(n)= g(n).
The greedy best first algorithm is implemented by the priority queue (or to store the heuristic
function value).
Best first search can switch between BFS and DFS, thus gaining the advantages of both
the algorithms.
Consider the following example for better understanding of greedy Best-First search algorithm.
Example1: Consider the following example (graph) with heuristic function value h(n)[Fig 2]
which illustrate the greedy Best-first search. Note that in the following example, heuristic
function is defined as
A 7 D
11 14 25
B C 10
F
8 20
15
9 10 G
E
H
Let heuristic function value h(n) for each node n to goal node G is defined as
The nodes added/deleted from OPEN and CLOSED list using Best-First Search algorithm are
shown below.
OPEN CLOSED
[A] []
[C,B,D] [A]
B,D A,C
F,E,B,D A,C
G.E.B.D A,C,F
E,B,D A,C,F,G
4
12 A B
9
8 E F
I G 2
0
Time Complexity:
Space Complexity:
The worst-case space complexity of Greedy best first search is O(bm). Where, m is the maximum
depth of the search space.
Complete: Greedy best-first search is also incomplete, even if the given state space is finite.
Example3: Apply Greedy Best-First Search algorithm on the following graph (L is a goal node).
Evaluation
10
function D
Start
E
node 2 8
A
F
6 13
s
B G
14 1
5 I K
5 0 Goal
C 7 L Node
H
6
J 2 M
Working: We start with a start-nodes, S. Now, S has three children i.e., A, B and C with their Heuristic
function values 2, 6 and 5 respectively. These weights show approximately, how far theyare from goal
node. So, we write, children of S are -(A:2), (B: 6), (C:5)
Out of these, the node with minimum value is (A : 2). So, we select A and its children are explored (or
generated).
Its children are(D: 10) and (E:8)
The search process now has four nodes to search for, namely-
(B : 6), (C: 5), (8.10) and (E: 8)
Out of these, node-C has the minimal value of 5. So, we select it and expand. So, we get(H: 7) as its child.
Now, the nodes to search are as follows-
(B:6), (D: 10,(E: 8) and (H : 7) and so on.
Step Node Children (on Available nodes (to search) Node Chosen
being expansion)
expanded
1. S (A:2), (B:6),(C:5) (A:2), (B:6),(C:5) (A:2)
2. A (D:10), (E:8) (B:6),(C:5), (D:10), (E:8) (C:5)
3. C (H:7) (B:6), (D:10), (E:8),(H:7) (B:6)
4. B (F:13), (G:14) (D:10), (E:8), (H:7) ,(F:13), (G:14) (H:7)
5. H (I:5), (J:6) (D:10), (E:8),(F:13), (G:14), (I:5), (I:5)
(J:6)
6. I (K:1), (L:0), (M:2) (D:10), (E:8), (H:7) ,(F:13), Goal node is found.
(G:14), (J:6),(K:1),(L:0),(M:2) So, search stops now
3.8 A* Algorithm
A* search is the most commonly known form of best-first search. It uses heuristic function h(n),
and cost to reach the node n from the start state g(n). It has combined features of uniform cost
search (UCS) and greedy best-first search, by which it solves the problem efficiently. A* search
algorithm finds the shortest path through the search space using the heuristic function. This
search algorithm expands less search tree and provides optimal result faster.
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 (Evaluation
Function).
f(n) = g(n) + h(n)
Estimated cost of the Cost to reach node n Cost to reach from node
cheapest solution. from start state. n to goal node.
If h(n) is admissible then search will find optimal solution. Admissible means underestimates cost of any
solution which can reached from node. In other words, a heuristic is called admissible if it always under-
estimates, that is, we always have ℎ(𝑛) ≤ ℎ∗ (𝑛), where h*(n) denotes the minimum distance to a goal
state from state n.
A* search begins at root node and then search continues by visiting the next node which has the least
evaluation value f(n).
It evaluates nodes by using the following evaluation function
f(n) = h(n) +g(n) = estimated cost of the cheapest solution through n.
Where,
g(n): the actual shortest distance traveled from initial node to current node, it helps to avoid expanding
paths that are already expansive
h(n): the estimated (or “heuristic”) distance from current node to goal, it estimates which node is closest
to the goal node.
Nodes are visited in this manner until a goal is reached.
Suppose s is a start state then calculation of evaluation function f(n) for any node n is shown in following
figure 10.
s
g(n)
n f(n) = g(n)+h(n)
Algorithm A*
In step5, we generate a successor of n (say m) and for each successor m, if it does not belong to
OPEN or CLOSED that is 𝑚 ∉ [𝑂𝑃𝐸𝑁 ∪ 𝐶𝐿𝑂𝑆𝐸𝐷], then we insert it in OPEN with the cost
g(n)+C(n,m) i.e., cost up to n and additional cost from n m.
If 𝑚 ∈ [𝑂𝑃𝐸𝑁 ∪ 𝐶𝐿𝑂𝑆𝐸𝐷] then we set g(m) with original cost and new cost [𝑔(𝑛) + 𝐶(𝑛, 𝑚)].
If we arrive at some state with another path which has less cost from original one, then we
replace the existing cost with this minimum cost.
If we find f(m) is decreased (if larger then ignore) and 𝑚 ∈ 𝐶𝐿𝑂𝑆𝐸𝐷 then move m from
CLOSED to OPEN.
Note that, the implementation of A* Algorithm involves maintaining two lists- OPEN and
CLOSED. The list OPEN contains those nodes that have been evaluated by the heuristic
function but have not expanded into successors yet and the list CLOSED contains those nodes
that have already been visited.
See the following steps for working of A* algorithm:
Step-1: Define a list OPEN. Initially, OPEN consists of a single
node, the start node S.
Step-2: If the list is empty, return failure and exit.
Step-3: Remove node n with the smallest value of f(n) from OPEN
and move it to list CLOSED.
If node n is a goal state, return success and exit.
Step-4: Expand node n.
Step-5: If any successor to n is the goal node, return success and the
solution by tracing the path from goal node to S.
Otherwise, go to Setp-6.
Step-6: For each successor node,
Apply the evaluation function f to the node.
If the node has not been in either list, add it to OPEN.
Step-7: Go back to Step-2.
Example1: Let’s us consider the following graph to understand the working of A* algorithm.
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.
10
A 3
6
6
1 F
7
8 B 2 5 G
H 3
D 7 3 1
3
1 2
I
C 8
5 5
5 3
E
3 5 J
Step-1:
We start with node A. Node B and Node F can be reached from node A. A* Algorithm
calculates f(B) and f(F). Estimated Cost f(n) = g(n) +h(n) for Node B and Node F is:
f(B) = 6+8=14
f(F) = 3+6=9
State h(n)
S 5
A 3
B 4
C 2
D 6
G 0
Solution:
S→A=1+3=4
S→G=10+0=10
S→A→B=1+2+4=7
S→A→C=1+1+2=4
S→A→C→D=1+1+3+6=11
S→A→C→G=1+1+4=6
S→A→B→D=1+2+5+6=14
S→A→C→D→G=1+1+3+2=7
S→A→B→D→G=1+2+5+2=10
3.8.2 Advantages and disadvantages of A* algorithm
Advantages:
A* search algorithm is the best algorithm than other search algorithms.
A* search algorithm is optimal and complete.
This algorithm can solve very complex problems.
Disadvantages:
It does not always produce the shortest path as it mostly based on heuristics and
approximation.
A* search algorithm has some complexity issues.
The main drawback of A* is memory requirement as it keeps all generated nodes in the
memory, so it is not practical for various large-scale problems.
In other words, if the heuristic function h always underestimates then true cost h* (that is heuristic
function cost h(n) is smaller than true cost h*(n)), then A* is guaranteed to find an optimal solution.
If there is a path from s to a goal state, A* terminates (even when the state space is infinite). Algorithm
A* is admissible, that is, if there is a path from s to a goal state, A* terminates by finding an optimal path
. If we are given two or more admissible heuristics, we can take there max to get a stronger admissible
heuristic.
Admissibility Condition :
By admissible algorithm. we mean that the algorithm is sure to find a most optimal solution if one exists.
Please note that this is possible only when the evaluation function value never overestimates the distance
of the node to the goal. Also note that if the evaluation function value which is a heuristic one is exactly
the same of the distance of the node to the goal, then this algorithm will immediately give the solution.
For example, the A* algorithm discussed above is admissible. There are three conditions to be satisfied
for A to be admissible.
They are as follows-
1. Each node in the graph has finite number of successors (or O).
2. All arcs in the graph have costs greater than some positive amount, (say C).
3. For each node in the graph, n, h(n) ≤h’(n).
This implies that the heuristic guess of the cost of getting from node n to the goal is never an
overestimate. This is known as a heuristic condition. Only if these three conditions are satisfied, A* is
guaranteed to find an optimal (least) cost path. Please note that A* algorithm is admissible for any
node n if on such path, h'(n) is always less than or equal to h(n). This is possible only when the
evaluation function value never overestimates the distance of the node to the goal. Although the
admissibility condition requires h'(n) to be a lower bound on h(n), it is expected that the more closely
h'(n) approaches h(n), the better is the performance of the algorithm.
If h(n) = h’(n) -an optimal solution path would be found without over expanding a node of the path. We
assume that one optimal solution exists. If h'(n)=0 then A* reduces to blind uniform cost algorithm or
breadth-first algorithm.
Please note that the admissible heuristics are by nature optimistic because they think that the cost of
solving the problem is less than it actually is because g(n) is the exact cost for each n. Also note that f(n)
should never overestimate the true cost of a solution through n.
For example, consider a network of roads and cities with roads connecting these cities. Our problems to
find a path between two cities such that the mileage/fuel cost is minimal. Then an admissible heuristic
would be to use distance to estimate the costs from a given city to the goal city. Naturally, the air distance
will be either equal to the real distance or will underestimate it i.e., h(n) ≤ h’(n).
1. A* is admissible: Algorithm A* is admissible , that is, if there is a path from S to goal state,
A* terminates by finding an optimal solution.
2. A* is complete: If there is a path from S to goal state, A terminates (Even when the state
space is ∞).
3. Dominance property: If A1& A2→ two Admissible versions of A* S.t.
A1 is more informed than A2, then A2 expends at least as many states as does A1. (So A1
dominates A2 Here, b/s its better heuristics than A 2)
If we are given two or more admissible heuristics, we can take their max to get a stronger
admissible heuristic.
Problem reduction search is broadly defined as a planning how best to solve a problem that can
be recursively decomposed into subproblems in multiple ways. There are many ways to
decompose a problem, we have to find the best decomposition, which gives the quality of
searching or cost is minimum.
We already know about the divide and conquer strategy, a solution to a problem can be obtained
by decomposing it into smaller sub-problems. Each of this sub-problem can then be solved to get
its sub solution. These sub solutions can then be recombined to get a solution as a whole. That is
called is Problem Reduction. This method generates arc which is called as AND arcs. One
AND arc may point to any number of successor nodes, all of which must be solved for an arc to
point to a solution.
When a problem can be divided into a set of sub problems, where each sub problem can be
solved separately and a combination of these will be a solution, AND-OR graphs or AND - OR
trees are used for representing the solution. The decomposition of the problem or problem
reduction generates AND arcs. Consider the following example to understand the AND-OR
graph (figure-11).
AND
OR
Fig 11AND-OR graph
The figure-11 shows an AND-OR graph. In an AND-OR graph, OR node represents a choice
between possible decompositions, and an AND node represents given decomposition. For
example, to Get a bike, we have two options, either:
1.(Steal a bike)
OR
2. Get some money AND Buy a Bike.
In this graph we are given two choices, first Steal a bike or get some money AND Buy a Bike.
When we have more than one choice and we have to pick one, we apply OR condition to choose
one.(That's what we did here).
Basically, the ARC here denotes AND condition.
Here we have replicated the arc between the Get some money and buy a bike because by getting
some money possibility of buying a bike is more than stealing.
AO* search algorithm is based on AND-OR graph, so it is called AO* search algorithm. AO*
Algorithm basically based on problem decomposition (Breakdown problem into small pieces).
The main difference between the A*(A star) and AO*(AO star) algorithms is that A* algorithm
represents an OR graph algorithm that is used to find a single solution (either this or that).
Butan AO* algorithm represents an AND-OR graph algorithm that is used to find more than
one solution by ANDing more than one branch.
A* algorithm guarantees to give an optimal solution while AO* doesn’t since AO* doesn’t
explore all other solutions once it got a solution.
Given [G, s, T]
Where G: Implicitly specified AND/OR graph
s: Strat node of the AND/OR graph
T: Set of terminal nodes (called SOLVED)
h(n): Heuristic function estimating the cost of solving the sub
problem at n.
Example1:
Let us see one example with the presence of heuristic value at every node (see fig 2) . The
estimated heuristic value is given at each node. The heuristic value h(n) at any node indicates
“from this node at least h(n) value (or cost) is required to find solution”. Here we assume the
edge cost value (i.e., g(n) value) for each edge is 1. Remember in OR node we always mark that
successor node which indicates best path for solution.
S
1 1 1
7 A 12 B C 13
1 1 1 1
5 D E 6 5 F G 7
H
Fig 12: AND-OR graph with heuristic value at each node
Note that, the graph given in fig 2, there are two paths for solution from start state S: either S-A-
B or S-C. To calculate the cost of the path we use the formula f(n)=g(n)+h(n) [note that here g(n)
value is 1 for every edge].
Path1: f(S-A-B)=1+1+7+12=21
Path2: f(S-C)=1+13=14
Since 𝑚𝑖𝑛(21,14) = 14; so, we select successor node C, as its cost is minimum, so it indicates
best path for solution.
Note that C is a AND node; so, we consider both the successor node of C. The cost of node C is
f(C-F-G)=1+1+5+7=14; so, the revised cost of node C is 14 and now the revised cost of node S
is f(S-C)=1+14=15 (revised).
Note that once the cost (that is f value) of any node is revised, we propagate this change
backward through the graph to decide the current best path.
Now let us explore another path and check whether we are getting lessor cost as compared to this
cost or not.
F(A-D)=1+5=6 and f(A-E)=1+6=7; since A is an OR node so best successor node is D since
min(6,7)=6. So revised cost of Node A will be 6 instead of 7, that is f(A)=6 (revised). Now next
selected node is D and D is having only one node H so f(D-H)=1+2=3, so the revised cost of
node D is 3, so now the revised cost of node A, that is f(A-D-H)=4. This path is better than f(A-
E)=7. So, the final revised cost of node A is 4. Now the final revised cost of f(S-A-
B)=1+1+4+12=18 (revised).
Thus, the final revised cost for
Path1: f(S-A-B)=18 and
Path2: f(S-C)=15
So optimal cost is 15.
Example2:
Consider the following AND-OR Graph with estimated heuristic cost at every node. Note that
A,D,E are AND node and B, C are OR node. Edge cost (i.e., g(n) value) is also given.
Apply AO* algorithm and find the optimal cost path using AO* algorithm.
A h=7
2 1 A,D,E → AND Node
B,C → OR Node
h=4 B C
2 1 0 0
h=2 D E 6 9 F G 7
1 0 0 0
3 H 10 I J 4 K 3
Heuristic (Estimated) cost at every Node is given. For example, heuristic cost at node A is h=7,
which means at least 7-unit cost required to find a solution.
Since A is AND Node, so we have to solve Both of its successor Node B and C.
Cost of Node A i.e., f(A-B-C) = (2+4) + (1+3) = 10
We perform cost revision in Bottom-up fashion.
h=4 B C h=3
A h=14
2 1
h=4 B C h=7
0 0
9 F G 7
Note that all the leaf Node in the Marked tree is solved is solved. So, the best way to solve the problem is
to following the marked tree and solving those marked problem. This best cost to solve the problem is 18.
Note that for AND Node: if both successor (unit problem) is solved, then we declared SOLVED and for
OR Node: if any one best successor is SOLVED, then we declared SOLVED.
Our real-life situations cannot be exactly decomposed into either AND tree or OR tree but is
always combination of both. So, we need an AO* algorithm where O stands for 'ordered'. Instead
of two lists OPEN and CLOSED of A* algorithm, we use a single structure GRAPH in AO*
algorithm. If represents a part of the search graph that has been explicitly generated so far. Please
note that each node in the graph will point both down to its immediate successors and to its
immediate predecessors. Also note that each node will have some h'(n) value associated with it.
But unlikeA* search, g(n) is not stored. It is not possible to compute a single value of g(n) due to
many paths to the same state. It is not required also as we are doing top-down traversing along
best-knownpath.
This guarantees that only those nodes that are on the best path are considered for expansion
Hence, h'(n) will only serve as the estimate of goodness of a node.
Next, we develop an AO* algorithm.
Algorithm AO*
1. Initialize: Set G* ={s}, f(s) =h(s)
If s ∈ T, label s as SOLVED
2. Terminate: If s is SOLVED, then Terminate
3. Select: Select a non-terminal leaf node n from the
marked
sub-free
4. Expand: Make explicit the successors of n for each new
successors, m:
Set f(m) =h(m)
If m is terminal, label m SOLVED
5. Cost Revision: Call Cost-Revise (n)
6. Loop: Go to Step 2.
Cost Revision in AO*: Cost-Revise(n)
1. Create Z = {n}
2. If Z = {} return
3. Select a node m from Z such that m has no descendants in Z
4. If m is an AND node with successors 𝑟1, 𝑟2, … 𝑟𝑘:
Set 𝑓(𝑚) = ∑ [𝑓(𝑟 ) + 𝑐(𝑚, 𝑟 )]
Mark the edge to each successor of m
If each successor is labelled SOLVED,
then label m as SOLVED.
Note that AO* will always find a minimum cost solution if one exists ifℎ’(𝑛) < ℎ(𝑛)and that all arc
costs are positive. The efficiency of this algorithm will depend on how closelyℎ’(𝑛) approximates ℎ(𝑛).
Also note that AO* is guaranteed to terminate even on graphs that have cycles.
Note: When the graph has only OR node then AO* algorithm works just like A* algorithm.
The following are the commonly used memory bound heuristics search:
IDA* is a variant of the A* search algorithm which uses iterative deepening to keep the memory usage
lower than in A*.It is an informed search based on the idea of the uniformed iterative deepening search.
Iterative deepening A* or IDA* is similar to iterative-deepening depth-first, but with the
following modifications:
f1
f2
f3
f4
A B C
f=120 f=130 f=120
D G E F
f=140 f=125 f=140 f=125
A B C
f=120 f=130 f=120
D G E F
f=140 f=125 f=140 f=125
f-limited, f-bound
P
f=100
A B C
f=120 f=130 f=120
D G E F
f=140 f=125 f=140 f=125
SUCC
3.10.3 Analysis of IDA*
IDA* is complete, optimal, and optimally efficient (assuming a consistent, admissible heuristic),
and requires only a polynomial amount of storage in the worst case:
S
F* = optimal path cost to a goal
𝑓∗ b
B = branching factor
𝛿
𝛿= minimum operator step cost
∗
nodes of storage required
Note that IDA* is complete & optimal Space usage is linear in the depth of solution. Each
iteration is depth first search, and thus it does not require a priority queue.
Iterative Deepening Search (IDS) is nothing but BFS plus DFS for tree search.
IDA* algorithm is “complete and Optimal” algorithm.
BFA and A* is good for optimality, but not memory.
DFS: good for memory O(bd), but not optimality
In the worst case, only one new state is expanded in each iteration
(IDA*). If A* expands N states, then IDA* can expand:
1+2+3+…+N=O(N2)
The idea of recursive best first search is to simulate A* search with O(bd) memory, where b is
the branching factor and d is the solution depth.
It is a memory bound, simple recursive algorithm that works like a standard best first search but
only takes up linear space. There are some things that make it different from recursive DFS. It
keeps track of f, the value of the best alternative path that can be found from any ancestor of the
current node, instead of continuing indefinitely down the current path.
RBFS mimic the operation of standard Best-First search algorithm. IBFS keep track of the f-
value of the best alternative path available from any ancestor of the 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 subtree at some later time.
RBFS is somewhat most efficient than IDA*, but still suffers from excessive node regeneration.
A* and RBFS are optimal algorithms if heuristic function h(n) is admissible.
12 10 16 15
2 1 2
1 2 3 4
1 3 3 1
7 11
12 5 6 7 8 15
5 5
1 4 10 0 15
0
12 9 10 11 12 0
8 3 1
4
5
1
3 2
4 2 3 23
4 3
4 2
5 3
20
6 0
Q.4: Apply AO* algorithm on the following graph. Heuristic value is also given at every node
and assume the edge cost value of each node is 1.
9
A
1 1 1
3 B 4 C D 5
1 1 1 1
5 E F 7 4 G H 4
Q.5 Apply AO* algorithm on the following graph. Heuristic value is also given at every node
and assume the edge cost value of each node is 1.
P
\ \
\
5 q r 11 s 8
\ \ \
\ \
4 t u v w x
7 1 3 3
\
y
1
Example 6: Given the 3 matrices A1, A2, A3 with their dimensions (3 × 4), (4 × 10), (10 × 1).
Consider the problem of solving this chain matrix multiplication. Apply the concept of AND-
OR graph and find a minimum cost solution tree.
3.12 Summary
As the name ‘Uninformed Search’ means the machine blindly follows the algorithm
regardless of whether right or wrong, efficient or in-efficient.
These algorithms are brute force operations, and they don’t have extra information about
the search space; the only information they have is on how to traverse or visit the nodes
in the tree. Thus, uninformed search algorithms are also called blind search algorithms.
The search algorithm produces the search tree without using any domain knowledge,
which is a brute force in nature. They don’t have any background information on how to
approach the goal or whatsoever. But these are the basics of search algorithms in AI.
The different types of uninformed search algorithms are as follows:
Depth First Search
Breadth-First Search
Depth Limited Search
Uniform Cost Search
Iterative Deepening Depth First Search
Bidirectional Search (if applicable)
The following terms are frequently used in any search algorithms:
To evaluate and compare the efficiency of any search algorithm, the following 4
properties are used:
3.13 Solutions/Answers
Answer 1:
Answer 2
Answer 4
Answer 1:
The OPEN and CLOSED list are shown below. Node with their f(n) values are inserted in OPEN list and
that node will be expended next whose f(n) value is minimum.
CLOSED
1(12) 2(12) 6(12) 5(13) 10(13) 11(13) 12(13)
OPEN
1(12)
2(12) 5(13)
5(13) 3(14) 6(12)
5(13) 3(14) 7(17) 10(13)
3(19) 7(17) 10(13)
3(19) 7(17) 10(13) 9(14)
3(19) 7(17) 9(14) 11(13)
3(19) 7(17) 9(14) 12(13)
Note that only 6 nodes are expended to reach to a goal node. Optimal cost to reach from start state (1) to
goal node (12) is 13.
Note: If all the edge cost is positive then Uniform cost search (UCS) algorithm is same as Dijkstra’s
algorithm. Dijkstra algorithm fails if graph is having a negative weight cycle. A* algorithm allows
negative weight also. It means A* algorithm work for negative (-ve) edge cost also. If some edge cost is
negative, then at any point of successive iteration, we cannot say till that node we have optimum cost
(because of the negative cost). So, in this case (-ve edge cost), nodes come back from CLOSED to OPEN.
Let us see one example (Example 2) having negative edge cost and you can also see how nodes come
back from CLOSED to OPEN.
Answer 2:
The OPEN and CLOSED list are shown below. Node with their f(n) values are inserted in OPEN list and
that node will be expended next whose f(n) value is minimum.
CLOSED
1(15) 2(7) 4(9) 5(11) 3(25) 4(7) 5(9)
OPEN
1(15)
2(7) 3(25)
3(25) 4(9)
3(25) 5(11)
3(25) 6(28) This is goal Node, but we can’t Pick this
4(7) 6(28) because better cost/path may exist.
Cost of 4 is decreased from 9 →7
so bring 4 from close →open 5(9) 6(28) (Note: In open 6(28) is Not min. cost ∴ we do not
pick them).
∴4(9) 6(26) 6(28)
Same Logic Goal (optimal cost is 26)
Optimal cost to reach from start state (1) to goal node (6) is 26.
3 B 4 C D 5
1 1 1 1
5 E F 7 4 G H 4
B 4 C D 10
1 1 1 1
5 E F 7 4 G H 4
Note that AO* algorithm does not explore all the solution path once it finds a solution.
[5×10]
[3×5] [3×6] [3×10]
A1 A2 A3 A1 A2 A3
(0) (300) (90) (0)
In this AND-OR graph, parent (root) node indicates the given problem for multiplying A1A2A3.
Next level of the tree (2 successors node) indicates the 2 choices (or ways) of multiplying (or
parenthesizing) the A1A2A3; first way is 𝐴1 × (𝐴2 × 𝐴3) and another way is (𝐴1 × 𝐴2) × 𝐴3.
Since out of these two choices, anyone will be the solution so there is a OR node for this. In an
OR node, we always mark the current best successor node. Next level we have an AND node.
For any AND node we must add the cost of both the successor node.
Cost of multiplying (𝐴2 × 𝐴3) = 5 × 6 × 10 = 300 and dimension of 𝐴2 × 𝐴3 is (5 × 10).
Since the dimension of A1 is (3 × 5) and the dimension of 𝐴2 × 𝐴3 is (5 × 10), so the cost of
multiplying 𝐴1 × (𝐴2 × 𝐴3) = 3 × 5 × 10 = 150. Thus the total cost will be 300+150=450.
Similarly,
The cost of multiplying (𝐴1 × 𝐴2) = 3 × 5 × 6 = 90 and dimension of 𝐴1 × 𝐴2 will be
(3 × 6). Since the dimension of 𝐴1 × 𝐴2 is (3 × 6) and the dimension of A3 is (6 × 10), so the
cost of multiplying (𝐴1 × 𝐴2) × 𝐴3 = 3 × 6 × 10 = 180. Thus the total cost will be
90+180=270. So, the best way to multiplying 𝐴1 × 𝐴2 × 𝐴3 is (𝐴1 × 𝐴2) × 𝐴3 and the
minimum cost of multiplying 𝐴1 × 𝐴2 × 𝐴3
is 270.
Answer 6: Option C
Answer 7: Option A