What is the time complexity of a breadth-first search (BFS) on a graph with V ve

Practice Questions

Q1
What is the time complexity of a breadth-first search (BFS) on a graph with V vertices and E edges?
  1. O(V)
  2. O(E)
  3. O(V + E)
  4. O(V * E)

Questions & Step-by-Step Solutions

What is the time complexity of a breadth-first search (BFS) on a graph with V vertices and E edges?
  • Step 1: Understand that a graph consists of vertices (V) and edges (E).
  • Step 2: Recognize that in a breadth-first search (BFS), we explore all the vertices and edges connected to the starting vertex.
  • Step 3: Note that during BFS, each vertex is visited once.
  • Step 4: Also note that each edge is considered once when exploring the vertices.
  • Step 5: Combine the visits: since we visit each vertex (V) and each edge (E) once, the total work done is proportional to V + E.
  • Step 6: Therefore, the time complexity of BFS is expressed as O(V + E).
No concepts available.
Soulshift Feedback ×

On a scale of 0–10, how likely are you to recommend The Soulshift Academy?

Not likely Very likely