Skip to content

Commit 58342df

Browse files
committed
add space complexity
1 parent 60cd296 commit 58342df

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Graphs/graphs_bfs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
vertices and E is the number of edges in the graph. This is because BFS traverses all the vertices
1919
and edges of the graph exactly once, and the time taken to visit each vertex and edge is constant.
2020
Therefore, the time complexity of BFS is proportional to the size of the graph.
21+
22+
The space complexity of BFS is O(|V|), where |V| is the number of vertices in the graph.
23+
This is because in the worst case scenario, we would need to store all vertices in the queue
24+
before we finish traversing the graph.
2125
*/
2226
package main
2327

0 commit comments

Comments
 (0)