Which data structure is used to find the shortest path in an unweighted graph?

Which data structure is used to find the shortest path in an unweighted graph?

a) Stack
b) Queue
c) Priority Queue
d) Array

Answer:

b) Queue

Explanation:

Breadth-First Search (BFS), which uses a queue, is used to find the shortest path in an unweighted graph. BFS explores all vertices at the current level before moving on to the next, ensuring that the shortest path is found in terms of the number of edges.

BFS works efficiently for unweighted graphs because it treats each edge as having equal weight. As it explores each node level by level, the first time a node is reached, the shortest path to that node is guaranteed.

In weighted graphs, algorithms like Dijkstra’s algorithm, which uses a priority queue, are more suitable for finding the shortest path.

Reference:

DSA (Data Structures and Algorithms) MCQ Questions and Answers

Scroll to Top