Uninformed Search
Uninformed search strategies (also known as blind
search strategies) are methods of exploring a problem
space without any domain-specific knowledge beyond
the problem definition. These strategies do not use
any information about how close a state is to the goal
—they treat all paths equally until a solution is found.
Examples:
Breadth-First Search, Uniform-Cost Search,
Depth-First Search, Depth-Limited Search,
Iterative Deepening, and Bidirectional
Search
1
Breadth-first search
• Breadth-first search (BFS) is an algorithm for traversing or
searching tree or graph data structures.
• It starts at the tree root (or some arbitrary node of a graph,
sometimes referred to as a ‘search key’), and explores all of
the neighbor nodes at the present depth prior to moving on
to the nodes at the next depth level.
• It is implemented using a queue(FIFO).
• BFS traverses the tree “shallowest(one step away) node first”,
it would always pick the shallower branch until it reaches the
solution (or it runs out of nodes, and goes to the next
branch).
Algorithm
BFS(Graph, start_node):
1. Initialize an empty queue Q
2. Initialize an empty array as visited
3. Enqueue the start_node into Q
4. Add start_node to visited
5. While Q is not empty:
a. Dequeue the front node from Q and call it current_node
b. Process current_node (e.g., print it or check if it's the goal)
c. For each neighbor of current_node:
i. If neighbor is not in visited:
- Add neighbor to visited
- Enqueue neighbor into Q
3
Example
Step1: Initially queue and visited
of BFS
Step2: Push node 0 into queue and
arrays are empty. mark it visited.
Step 3: Remove node 0 from the front of Step 4: Remove node 1 from the front of
queue and visit the unvisited neighbours queue and visit the unvisited neighbours
and push them into queue. and push them into queue.
4
Step 5: Remove node 2 from the Step 6: Remove node 3 from the front of
front of queue and visit the unvisited queue and visit the unvisited neighbours
neighbours and push them into and push them into queue.
queue. As we can see that every neighbours of
node 3 is visited, so move to the next
node that are in the front of the queue.
Steps 7: Remove node 4 from the front of
queue and and visit the unvisited
neighbours and push it hem into queue.
As we can see that every neighbours of
node 4 are visited, so move to the next
node that is in the front of the queue.
Now, Queue becomes empty, So,
terminate these process of iteration.
5
Example-2
6
Advantages
•BFS will provide a solution if any solution exists.
•If there are more than one solution for a given problem, then
BFS will provide minimum solution which requires the least
number of steps.
Disadvantage
•It requires lot of memory since each level of the tree must be
saved into memory to expand the next level.
•BFS needs lot of time if the solution is far a way from the root.
7
Time complexity: Equivalent to the number of
nodes traversed in BFS until the shallowest
solution. T(n) = 1 + n^2 + n^3 + ... + n^s =
O(n^s)
•s = the depth of the shallowest solution.
•n^i = number of nodes in level i.
Space complexity: The auxiliary space
complexity of Breadth-First Search algorithm is
O(V), where V is the number of vertices in the
graph.
8
• Completeness: BFS is complete, meaning for a
given search tree, BFS will come up with a
solution if it exists.
• Optimality: BFS is optimal as long as the costs
of all edges are equal.