Let be an undirected graph with positive edge weights. Dijkstra’s single source shortest path algorithm can be implemented using the binary heap data structure with time complexity:
View worked solution
Answer: D
To find the time complexity of Dijkstra's single-source shortest path algorithm using a binary heap, we analyze the cost of the priority queue operations performed during the algorithm:
- Initialization: Inserting all vertices into the binary heap takes time.
- Extract-Min: The algorithm extracts the minimum-distance vertex from the heap exactly once for each vertex. Since there are vertices and each
Extract-Minoperation on a binary heap of size takes time, the total time for all extractions is: - Decrease-Key (Relaxation): For each edge processed, we may need to update the shortest path estimate of an adjacent vertex, which corresponds to a
Decrease-Keyoperation in the binary heap. In the worst case, this relaxation happens once for every edge, resulting in at mostDecrease-Keyoperations. Each such operation takes time in a binary heap. The total time for all relaxations is:
Summing these components, the total worst-case time complexity is:
Comparison of options:
- Option A: is the complexity when using an unsorted array as the priority queue.
- Option B: is the complexity achieved when using a Fibonacci heap.
- Option D: is the correct complexity when using a binary heap.
Free practice · Your answers on this page are not saved.
