Sumanmondal 14871022056

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 5

FUTURE INSTITUTE OF ENGINEERING AND MANAGEMENT

Explain Breadth First Search in Artificial Intelligence.

CONTINUOUS ASSESSMENT #1
SUBJECT NAME :- Artificial Intelligence
SUBJECT CODE :- MCAN-302

STUDENT NAME :- SUMAN MONDAL

MAKAUT ROLL- 14871022056

MCA – 3rd sem

2023-24
Introduction of BFS
Breadth-first search (BFS) is an algorithm for traversing or searching Tree or Graph data structures.
BFS finds a path between two nodes by taking one step down all paths and then immediately
backtracking.

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. Often implemented by maintaining a queue of vertices to visit.

• BFS always returns the shortest path (the one with the fewest edges) between the start and the
end vertices.
Algorithm of BFS
1. In the various levels of the data, you can mark any node as the starting or initial node to begin
traversing. The BFS will visit the node and mark it as visited and places it in the queue.

2. Now the BFS will visit the nearest and un-visited nodes and marks them. These values are also added
to the queue. The queue works on the FIFO model.

3. In a similar manner, the remaining nearest and un-visited nodes on the graph are analyzed marked
and added to the queue. These items are deleted from the queue as receive and printed as the result.

● Visiting a node: Just like the name suggests, visiting a node means to visit or select a node

● Exploring a node: Exploring the adjacent nodes (child nodes) of a selected node
 Advantages of Breadth First Search:
1. BFS will never get trapped exploring the useful path forever.
2. If there is a solution, BFS will definitely find it.
3. If there is more than one solution then BFS can find the minimal one that requires less number
of steps.
4. Low storage requirement – linear with depth.
5. Easily programmable.

 Disadvantages of Breadth First Search:


The main drawback of BFS is its memory requirement. Since each level of the graph must be
saved in order to generate the next level and the amount of memory is proportional to the number
of nodes stored the space complexity of BFS is O(bd ), where b is the branching factor(the
number of children at each node, the outdegree) and d is the depth. As a result, BFS is severely
space-bound in practice so will exhaust the memory available on typical computers in a matter of
minutes.
Applications of Breadth First Search
1. AI: In AI, BFS is used in traversing a game tree to find the best move.
2. Shortest Path and Minimum Spanning Tree for unweight graph
3. Minimum Spanning Tree for weighted graphs
4. Peer-to-Peer Networks
5. Crawlers in Search Engines
6. Social Networking Websites
7. GPS Navigation systems
8. Broadcasting in Network
9. Network Security
10. Image processing

Time & Space complexity


s = the depth of the shallowest solution.
n^i = number of nodes in level i

● 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)
● Space complexity: Equivalent to how large can the fringe get. S(n) = O(n^s)
● 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.

You might also like