Practice mode Data Structures

Which data structure does breadth-first search (BFS) use to keep track of vertices still to be explored?

Correct answer D. Queue

Explanation

BFS explores all neighbours of a vertex before moving deeper, so vertices must be processed in the order they were discovered, which is FIFO. A queue provides exactly that. Using a stack instead turns the traversal into depth-first search. In an unweighted graph, BFS from a source therefore finds the paths with the fewest edges.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.