Questions: Breadth-First Search (BFS)

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

You run BFS on an unweighted graph from source vertex A. Vertex B is discovered when it is first dequeued at level 4. Can BFS later find a shorter path from A to B?

AYes — BFS might find a shorter path later if it hasn't explored all vertices yet
BNo — BFS guarantees that the first time a vertex is discovered, it is via the shortest path
CYes — BFS only guarantees shortest paths in trees, not graphs with cycles
DIt depends on whether the graph is directed or undirected
Question 2 Multiple Choice

You modify BFS to use a stack instead of a queue. What algorithm does this produce, and does it still find shortest paths?

ADijkstra's algorithm — it finds shortest paths in weighted graphs
BTopological sort — it still finds shortest paths but in topological order
CDepth-first search (DFS) — it does not guarantee shortest paths
DA faster variant of BFS that still guarantees shortest paths
Question 3 True / False

BFS visits all vertices at distance k from the source before visiting any vertex at distance k+1.

TTrue
FFalse
Question 4 True / False

Without the visited-marking step, BFS on a graph with cycles would eventually terminate because vertices would stop being enqueued once most paths are explored.

TTrue
FFalse
Question 5 Short Answer

Why does BFS guarantee finding the shortest path in an unweighted graph, while depth-first search (DFS) does not?

Think about your answer, then reveal below.