Queue can be used to implement
2013
Queue can be used to implement
- A.
DFS
- B.
BFS
- C.
Radix-Sort
- D.
Recursion
Attempted by 77 students.
Show answer & explanation
Correct answer: B
Concept
A queue is a linear data structure that follows the First-In-First-Out (FIFO) order: the element inserted earliest is the one removed first. Any algorithm that must process items in the exact order they were discovered relies on a queue to preserve that ordering.
Application
Breadth-First Search (BFS) explores a graph or tree level by level. Starting from a source, it must visit every neighbour of the current frontier before moving outward. To enforce this level-order, BFS enqueues each newly discovered vertex and dequeues vertices in the same order they were found — exactly the FIFO behaviour a queue provides.
Enqueue the start vertex and mark it visited.
Dequeue a vertex, then enqueue all its unvisited neighbours.
Repeat until the queue is empty; the FIFO order guarantees nearer vertices are processed before farther ones.
Contrast
Depth-First Search goes as deep as possible before backtracking, which needs Last-In-First-Out (LIFO) ordering, i.e. a stack — not a queue.
A self-calling traversal relies on the program's implicit call stack (LIFO), again a stack rather than a queue.
A digit-by-digit distribution sort groups keys into buckets; it is not a graph/tree traversal driven by a single FIFO ordering of discovered items.