Algorithms Analysis Practice Test 2025 – All-in-One Mastery Guide to Exam Success

Image Description

Question: 1 / 400

What is the time complexity of Dijkstra's algorithm using a priority queue?

O(V + E)

O(V log E)

O((V + E) log V)

Dijkstra's algorithm, when implemented with a priority queue (typically a binary heap), achieves a time complexity of O((V + E) log V).

Here’s a breakdown of how this complexity is derived:

1. **Vertex and Edge Processing**: In Dijkstra's algorithm, you start with a graph that has V vertices and E edges. The algorithm repeatedly extracts the vertex with the minimum distance from the priority queue, which takes O(log V) time due to the properties of the binary heap. Each vertex is extracted once, contributing O(V log V) to the overall complexity.

2. **Updating Distances**: Whenever a vertex is extracted, all of its adjacent edges (neighboring vertices) are explored, and if a shorter path to a neighboring vertex is found, the priority queue needs to update the vertex’s distance. The number of edges processed is E, and each of these updates can also take O(log V) time as it may require either an insertion or a decrease-key operation on the priority queue.

3. **Total Time Complexity**: Combining these actions, the time spent extracting vertices (O(V log V)) and updating distances (O(E log V)) results in a total time complexity of O((V +

Get further explanation with Examzify DeepDiveBeta

O(V^2)

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy