Question: What is the space complexity of BFS in a graph with V vertices?
Options:
O(V)
O(E)
O(V + E)
O(1)
Correct Answer: O(V)
Solution:
BFS requires O(V) space for the queue to store the vertices at the current level.
What is the space complexity of BFS in a graph with V vertices?
Practice Questions
Q1
What is the space complexity of BFS in a graph with V vertices?
O(V)
O(E)
O(V + E)
O(1)
Questions & Step-by-Step Solutions
What is the space complexity of BFS in a graph with V vertices?
Step 1: Understand what BFS (Breadth-First Search) is. It is an algorithm used to explore nodes and edges of a graph level by level.
Step 2: Identify that BFS uses a queue to keep track of the vertices that need to be explored.
Step 3: Realize that in the worst case, BFS may need to store all the vertices in the queue at once, especially when exploring the last level of the graph.
Step 4: Note that the number of vertices in the graph is represented by V.
Step 5: Conclude that the space required for the queue in BFS is proportional to the number of vertices, which is O(V).
No concepts available.
Soulshift Feedback×
On a scale of 0–10, how likely are you to recommend
The Soulshift Academy?