Open In App

Time and Space Complexity of Breadth First Search (BFS)

What is Breadth First Search?

The Breadth First Search (BFS) algorithm is used to search a graph data structure for a node that meets a set of criteria. It starts at the root of the graph and visits all nodes at the current depth level before moving on to the nodes at the next depth level.

Although there are other methods for traversing the graph, BFS is the one that is most frequently employed. The method to search every vertex in a tree or graph data structure is recursive. Each vertex in the graph is classified as visited or non-visited using BFS. It looks at every node that is next to the node it has chosen in a graph after picking just one.



Time Complexity of Breadth First Search (BFS):

Best Case: O(V + E)

Average Case: O(V + E)



Worst Case: O(V + E)

Auxiliary Space of Breadth First Search (BFS):

The auxiliary space complexity of Breadth-First Search algorithm is O(V), where V is the number of vertices in the graph. Here’s why the auxiliary space complexity is O(V):

Queue Data Structure:

Visited Array:

Additional Space:

Article Tags :