Open In App

Breadth-first Search is a special case of Uniform-cost search

Improve
Improve
Like Article
Like
Save
Share
Report

In AI there are mainly two types of search techniques:

  1. Un-informed/blind search techniques
  2. Informed search techniques

Search algorithms under the Uninformed category are:

  1. Breadth-first search
  2. Uniform cost search
  3. Depth-first search
  4. Depth limited search
  5. Iterative deepening depth-first search
  6. Bidirectional search

Search algorithms under the Informed category are:

  1. Best first search
  2. A* search

Now, we shall define the steps of BFS and UCS searches, then we will derive BFS from the UCS search algorithm.

Breadth-first search algorithm: 

Open list is implemented using Queue for BFS.

  1. Add the initial node x0 to the open list.
  2. Take a node x from the front-end of open list. If  the open list is empty then we can’t proceed further hence can’t find the target node. 
       (a) If open list is empty, stop with failure.
       (b) On the other hand, if x is the target node, stop with success.
  3. Expand x to obtain a set S of child nodes of x, and put x into the closed list.
  4. For each node x’ in set S, if it is not in the closed list, add it to the open list along with the edge (x, x’).
  5. Return to Step 2.

Property of BFS:

  1. It is a complete search in the sense that it can always find the solution in the finite steps in the finite search graph.
  2. The transition cost function is d(x, x’) = 1 or any constant.

Advantages of Breadth-First Search:

  1. It will find the shortest path between the starting point and any other reachable points.
  2. It always finds optimal solutions.
  3. There is nothing like a useless path in BFS since it searches level by level.
  4. Finds the closest goal in less time.

Uniform cost search algorithm:

  1. Add the initial node x0 and its cost C(x0) to the open list.
  2. Get a node x from the top of the open list.    (a) If the open list is empty then we can’t proceed further and hence can’t find the solution. So, if open list is empty then stop with failure.    (b) If  x is the target node then we can stop here. So, if x is target node then stop with success.
  3. Expand x to get a set S of the child nodes of x, and move x to the closed list.
  4. Pick each x’ from the set S which is not present in the closed list, find its accumulated cost: C(x’) = C(x) + d(x, x’).
  5. If x’ is not present in the open list: Add x’, C(x’) and (x, x’) to the open list.   (a) If x’ in already present in the open list, update its cost C(x’) and link (x, x’) in the open list if the new cost is smaller than old cost.
  6. Sort the open list based on the node costs, and return to step-2.

Properties of UCS:

  1. We can always find the best path from the initial node to the current node.
  2. C(x) is the accumulated cost of node x, from the initial node.
  3. d(x, x’) is the cost for state transition from node x to node x’.
  4. If we set d(x, x’)=1 for all edges, UCS becomes equivalent to Breadth-First Search.

Deriving BFS from UCS: 

The cost function in BFS: C(x’) = C(x) + 1 …(1)

The cost function in UCS: C(x’) = C(x) + d(x, x’) …(2)

C(x0) = 1 in BFS and UCS …(3)

If we make transition cost from node x to x’ = 1 then;

UCS: C(x’) = C(x) + 1 …(4)

Thus, from (1) and (4), we conclude that BFS is derived from UCS by making transition cost as 1.

Therefore, BFS is a special case of UCS.

How uniform-cost search is a special case of A* search – Artificial Intelligence

  1. Add the initial node x0 and its cost C(x0) to the open list.
  2. Get a node x from the top of the open list.    (a) If the open list is empty then we can’t proceed further and hence can’t find the solution. So, if open list is empty then stop with failure.    (b) If  x is the target node then we can stop here. So, if x is target node then stop with success.
  3. Expand x to get a set S of the child nodes of x, and move x to the closed list.
  4. Pick each x’ from the set S which is not present in the closed list, find its accumulated cost: C(x’) = C(x) + d(x, x’).
  5. If x’ is not present in the open list: Add x’, C(x’) and (x, x’) to the open list.   (a) If x’ in already present in the open list, update its cost C(x’) and link (x, x’) in the open list if the new cost is smaller than old cost.
  6. Sort the open list based on the node costs, and return to step-2.

Properties of UCS:

  1. We can always find the best path from the initial node to the current node.
  2. C(x) is the accumulated cost of node x, from the initial node.
  3. d(x, x’) is the cost for state transition from node x to node x’.
  4. If we set d(x, x’)=1 for all edges, UCS becomes equivalent to Breadth-First Search.

A* search algorithm:

  1. Put the initial node x0 and its cost F(x0)=H(x0) to the open list.
  2. Get a node x from the top of the open list.
  3.  
    • (a) If the open list is empty then we can’t proceed further and hence can’t find the solution. So, if open list is empty then stop with failure.
    • (b) If  x is the target node then we can stop here. So, if x is target node then stop with success.
  4. Expand x to get a set S of child nodes. Put x to the closed list.
  5. H(x) = Heuristic cost of reaching upto state x from initial state.
  6. d(x, x’) = cost of state transition from state x to state x’.
  7. For each x’ in S, find its cost: C(x’)=C(x)+d(x,x’)
  8.  
    • (a)  If x’ is in the closed list but the new cost is smaller than the old one, move x’ to the open list and update the edge (x,x’) and the cost.
    • (b) Else, if x’ is in the open list, but the new cost is smaller than the old one, update the edge (x,x’) and the cost.
    • (c)Else (if x’ is not in the open list nor in the closed list), put x’ along with the edge (x,x’) and the cost F to the open list.
    • (d) Sort the open list according to the costs of the nodes, and return to Step 2.

A* algorithm promises the best optimal solution.

Deriving UCS from A* algorithm:

Cost function in UCS: C(x’) = C(x} + d(x, x’) …(1)

Cost function in A*: F(x’) = F(x) + d(x, x’) + [H(x’) – H(x)] …(2)

Put H(x) = 0, for all nodes x.

Substitute H(x) = 0, in equation (2).

We get: F(x’) = F(x) + d(x, x’) + [0 – 0]

where F(x) = cost of reach state x.

Hence, F(x) = C(x)

Thus, A* becomes UCS if heuristic cost of every node is 0. So, UCS is a special case of A* algorithm.


Last Updated : 06 Mar, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads