Machine-translated by Google. Questions are authored in English.
Top

Discussion

In breadth first search of a graph, which data structure is used to hold nodes ?

  • A.Array
  • B.Queue
  • C.Stack
  • D.Graph

Answer: B

Breadth-first search uses a queue.

BFS visits vertices level by level. Discovered vertices are added to the rear of a first-in, first-out queue, and the next vertex to explore is taken from the front, so all vertices at distance k are processed before any at distance k + 1.

A stack, last-in first-out, gives depth-first search instead. An array can store the graph or the visited flags but does not by itself impose the FIFO order, and 'graph' is the structure being searched, not the holder of pending nodes.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.