To implement Dijkstra's shortest path algorithm on unweighted graphs so that…

2025

To implement Dijkstra's shortest path algorithm on unweighted graphs so that it runs in linear time, the data structure to be used is

  1. A.

    Queue

  2. B.

    B-tree

  3. C.

    Stack

  4. D.

    Heap

Attempted by 80 students.

Show answer & explanation

Correct answer: A

Dijkstra's algorithm is typically used for weighted graphs and relies on a priority queue (often implemented as a heap) to efficiently select the next vertex with the smallest tentative distance. However, in unweighted graphs, every edge has a uniform weight (usually 1). This means that the order in which vertices are visited follows a simple breadth-first pattern. Instead of using a complex priority queue or heap, we can use a standard First-In-First-Out (FIFO) Queue. By processing vertices in the order they are discovered, we ensure that each vertex is visited at its minimum distance level before moving to the next. This approach effectively transforms Dijkstra's algorithm into Breadth-First Search (BFS), which runs in linear time O(V + E). A B-tree is used for database indexing and does not manage traversal order. A Stack would lead to Depth-First Search (DFS), which does not guarantee shortest paths in unweighted graphs. Therefore, a Queue is the optimal data structure for this specific scenario.

Explore the full course: Tpsc Assistant Technical Officer