Uninformed Search Algorithms
Uninformed Search Algorithms
1. Breadth-first Search
2. Depth-first Search
3. Depth-limited Search
4. Iterative deepening depth-first search
5. Uniform cost search
6. Bidirectional Search
7.
1. Breadth-first Search:
o Breadth-first search is the most common search strategy for
traversing a tree or graph. This algorithm searches breadthwise
in a tree or graph, so it is called breadth-first search.
o BFS algorithm starts searching from the root node of the tree
and expands all successor node at the current level before
moving to nodes of next level.
o The breadth-first search algorithm is an example of a general-
graph search algorithm.
o Breadth-first search implemented using FIFO queue data
structure.
Advantages:
o BFS will provide a solution if any solution exists.
o If there are more than one solutions for a given problem, then
BFS will provide the minimal solution which requires the least
number of steps.
Disadvantages:
Example:
In the below tree structure, we have shown the traversing of the tree
using BFS algorithm from the root node S to goal node K.
1. S---> A--->B---->C--->D---->G--->H--->E---->F---->I---->K
Time Complexity: Time Complexity of BFS algorithm can be
obtained by the number of nodes traversed in BFS until the shallowest
Node. Where the d= depth of shallowest solution and b is a node
at every state.
2. Depth-first Search
o Depth-first search is a recursive algorithm for traversing a tree
or graph data structure.
o It is called the depth-first search because it starts from the root
node and follows each path to its greatest depth node before
moving to the next path.
o DFS uses a stack data structure for its implementation.
o The process of the DFS algorithm is similar to the BFS
algorithm.
Advantage:
Disadvantage:
Example:
In the below search tree, we have shown the flow of depth-first
search, and it will follow the order as:
It will start searching from root node S, and traverse A, then B, then D
and E, after traversing E, it will backtrack the tree as E has no
other successor and still goal node is not found.
After backtracking it will traverse node C and then G, and here it will
terminate as it found goal node.
Where, m= maximum depth of any node and this can be much larger
than d (Shallowest solution depth)
In this algorithm, the node at the depth limit will treat as it has
no successor nodes further.
Advantages:
Disadvantages:
Example:
Time Complexity: Time complexity of DLS algorithm is O(bℓ).
Advantages:
Disadvantages:
Example:
Completeness:
Time Complexity:
Let C* is Cost of the optimal solution, and ε is each step to get closer
to the goal node. Then the number of steps is = C*/ε+1. Here we have
taken +1, as we start from state 0 and end to C*/ε.
Space Complexity:
The same logic is for space complexity so, the worst-case space
complexity of Uniform-cost search is O(b1 + [C*/ε]).
Optimal:
Advantages:
Example:
Following tree structure is showing the iterative deepening depth-first
search. IDDFS algorithm performs various iterations until it does not
find the goal node. The iteration performed by the algorithm is given
as:
1'st Iteration-----> A
2'nd Iteration----> A, B, C
3'rd Iteration------>A, B, D, E, C, F, G
4'th Iteration------>A, B, D, H, I, E, C, F, K, G
In the fourth iteration, the algorithm will find the goal node.
Completeness:
Let's suppose b is the branching factor and depth is d then the worst-
case time complexity is O(bd).
Space Complexity:
Optimal:
Advantages:
Disadvantages:
Example:
In the below search tree, bidirectional search algorithm is applied.
This algorithm divides one graph/tree into two sub-graphs. It starts
traversing from node 1 in the forward direction and starts from goal
node 16 in the backward direction.
It takes the current state of the agent as its input and produces the
estimation of how close agent is from the goal.
The heuristic method, however, might not always give the best
solution, but it guaranteed to find a good solution in reasonable time.
Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence
heuristic cost should be less than or equal to the estimated cost.
Pure Heuristic Search:
Pure heuristic search is the simplest form of heuristic search
algorithms.
It expands nodes based on their heuristic value h(n).
It maintains two lists, OPEN and CLOSED list.
In the CLOSED list, it places those nodes which have already
expanded
And in the OPEN list, it places nodes which have yet not been
expanded.
On each iteration, each node n with the lowest heuristic value is
expanded and generates all its successors and n is placed to the
closed list.
The algorithm continues unit a goal state is found.
In the informed search we will discuss two main algorithms which are
given below:
Advantages:
o Best first search can switch between BFS and DFS by gaining
the advantages of both the algorithms.
o This algorithm is more efficient than BFS and DFS algorithms.
Disadvantages:
o It can behave as an unguided depth-first search in the worst case
scenario.
o It can get stuck in a loop as DFS.
o This algorithm is not optimal.
Example:
Consider the below search problem, and we will traverse it using
greedy best-first search. At each iteration, each node is expanded
using evaluation function f(n)=h(n) , which is given in the below
table.
At each point in the search space, only those node is expanded which have the
lowest value of f(n), and the algorithm terminates when the goal node is found.
Algorithm of A* search:
Step1: Place the starting node in the OPEN list.
Step 2: Check if the OPEN list is empty or not, if the list is empty
then return failure and stops.
Step 3: Select the node from the OPEN list which has the smallest
value of evaluation function (g+h), if node n is goal node then return
success and stop, otherwise
Step 4: Expand node n and generate all of its successors, and put n
into the closed list. For each successor n', check whether n' is already
in the OPEN or CLOSED list, if not then compute evaluation function
for n' and place into Open list.
Advantages:
o A* search algorithm is the best algorithm than other search
algorithms.
o A* search algorithm is optimal and complete.
o This algorithm can solve very complex problems.
Disadvantages:
o It does not always produce the shortest path as it mostly based
on heuristics and approximation.
o A* search algorithm has some complexity issues.
o 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.
Example:
In this example, we will traverse the given graph using the A*
algorithm. The heuristic value of all states is given in the below table
so we will calculate the f(n) of each state using the formula f(n)= g(n)
+ h(n), where g(n) is the cost to reach any node from start state.
Here we will use OPEN and CLOSED list.
Solution:
Points to remember:
If the function on Y-axis is cost then, the goal of search is to find the
global minimum and local minimum.
2. Plateau: A plateau is the flat area of the search space in which all
the neighbor states of the current state contains the same value,
because of this algorithm does not find any best direction to move. A
hill-climbing search might be lost in the plateau area.
Solution: The solution for the plateau is to take big steps or very little
steps while searching, to solve the problem. Randomly select a state
which is far away from the current state so it is possible that the
algorithm could find non-plateau region.
Solution:
To solve the above problem, we will first find the differences between
initial states and goal states, and for each difference, we will generate
a new state and will apply the operators. The operators we have for
this problem are:
o Move
o Delete
o Expand
1. Evaluating the initial state: In the first step, we will evaluate the
initial state and will compare the initial and Goal state to find the
differences between both states.
2. Applying Delete operator: As we can check the first difference is
that in goal state there is no dot symbol which is present in the initial
state, so, first we will apply the Delete operator to remove this dot.
AND-OR Graph
In the above figure, the buying of a car may be broken down into smaller
problems or tasks that can be accomplished to achieve the main goal in the
above figure, which is an example of a simple AND-OR graph. The other
task is to either steal a car that will help us accomplish the main goal or use
your own money to purchase a car that will accomplish the main goal.
The AND symbol is used to indicate the AND part of the graphs, which
refers to the need that all subproblems containing the AND to be resolved
before the preceding node or issue may be finished.
The start state and the target state are already
known in the knowledge-based search strategy known as the AO*
algorithm, and the best path is identified by heuristics. The informed search
technique considerably reduces the algorithm’s time complexity. The AO*
algorithm is far more effective in searching AND-OR trees than the A*
algorithm.
Working of AO* algorithm:
The evaluation function in AO* looks like this:
f(n) = g(n) + h(n)
f(n) = Actual cost + Estimated cost
here,
f(n) = The actual cost of traversal.
g(n) = the cost from the initial node to the current node.
h(n) = estimated cost from the current node to the goal state.
Here, in the above example all numbers in brackets are the heuristic value
i.e h(n). Each edge is considered to have a value of 1 by default.
Step-1
Starting from node A, we first calculate the best path.
f(A-B) = g(B) + h(B) = 1+4= 5 , where 1 is the default cost value of
travelling from A to B and 4 is the estimated cost from B to Goal state.
f(A-C-D) = g(C) + h(C) + g(D) + h(D) = 1+2+1+3 = 7 , here we are
calculating the path cost as both C and D because they have the AND-Arc.
The default cost value of travelling from A-C is 1, and from A-D is 1, but the
heuristic value given for C and D are 2 and 3 respectively hence making
the cost as 7.
The minimum cost path is chosen i.e A-B.
Step-2
Using the same formula as step-1, the path is now calculated from the B
node,
f(B-E) = 1 + 6 = 7.
f(B-F) = 1 + 8 = 9
Hence, the B-E path has lesser cost. Now the heuristics have to be
updated since there is a difference between actual and heuristic value of B.
The minimum cost path is chosen and is updated as the heuristic , in our
case the value is 7. And because of change in heuristic of B there is also
change in heuristic of A which is to be calculated again.
f(A-B) = g(B) + updated((h(B)) = 1+7=8
Step-3
Comparing path of f(A-B) and f(A-C-D) it is seen that f(A-C-D) is smaller.
Hence f(A-C-D) needs to be explored.
Now the current node becomes C node and the cost of the path is
calculated,
f(C-G) = 1+2 = 3
f(C-H-I) = 1+0+1+0 = 2
f(C-H-I) is chosen as minimum cost path,also there is no change in
heuristic since it matches the actual cost. Heuristic of path of H and I are 0
and hence they are solved, but Path A-D also needs to be calculated ,
since it has an AND-arc.
f(D-J) = 1+0 = 1, hence heuristic of D needs to be updated to 1. And finally
the f(A-C-D) needs to be updated.
f(A-C-D) = g(C) + h(C) + g(D) + updated((h(D)) = 1+2+1+1 =5.
As we can see that the solved path is f(A-C-D).