BFS Time Complexity (Big-O)

Breadth-first search runs in O(V + E) time and O(V) space, exploring a graph layer by layer from a source vertex. It is the canonical algorithm for shortest paths in an unweighted graph.

Open the interactive DevRef Hub tool →

Key facts

TimeO(V + E)
SpaceO(V)
UseShortest path (unweighted)
OrderLayer by layer

Frequently asked questions

What is the time complexity of BFS?

O(V + E), where V is vertices and E is edges.

What is BFS used for?

Shortest path in an unweighted graph and level-order traversal.

Related pages

Big-O of BFS is part of DevRef Hub on GOAT Lab — a free reference you can use without signing up, and it works offline. Open the tool above for any custom value.

Advertise

Part of GOAT Lab — 26 free, browser-based science, engineering and developer tools. No sign-up.