What is the main goal of Dijkstra's algorithm in graph theory?
Think about what kind of paths Dijkstra's algorithm helps to find and what restrictions it has on edge weights.
Dijkstra's algorithm is designed to find the shortest paths from a single starting node to all other nodes in a graph where all edge weights are zero or positive. It does not work correctly with negative edge weights.
What happens if Dijkstra's algorithm is applied to a graph that contains negative edge weights?
Consider the assumptions Dijkstra's algorithm makes about edge weights and how negative weights affect path calculations.
Dijkstra's algorithm assumes all edge weights are non-negative. If negative weights exist, the algorithm can incorrectly calculate shortest paths because it does not revisit nodes once visited, missing shorter paths through negative edges.
Given the following weighted graph edges:
A-B: 4, A-C: 2, B-C: 5, B-D: 10, C-D: 3, D-E: 1, E-F: 2, F-D: 6
What is the shortest distance from node A to node E using Dijkstra's algorithm?
Trace the shortest path step-by-step from A to E considering the edge weights.
The shortest path from A to E is A -> C -> D -> E with distances 2 + 3 + 1 = 6. However, the total distance is 6, but option A is 7, so let's re-check carefully.
Paths:
- A-C (2), C-D (3), D-E (1) = 6
- A-B (4), B-D (10), D-E (1) = 15
- A-C (2), C-B (5), B-D (10), D-E (1) = 18
So the shortest distance is 6, which matches option A, but option A is 6, option A is 7. So correct answer is A.
Which of the following best describes the time complexity of Dijkstra's algorithm when implemented with a binary heap priority queue on a graph with V vertices and E edges?
Consider how the priority queue operations affect the complexity and how many edges and vertices are processed.
Using a binary heap, Dijkstra's algorithm runs in O((V + E) log V) time because each vertex is inserted into the priority queue once and each edge is relaxed once.
Why is a priority queue (min-heap) preferred over a simple queue when implementing Dijkstra's algorithm?
Think about how Dijkstra's algorithm decides which node to explore next.
Dijkstra's algorithm relies on always choosing the node with the smallest current distance to ensure the shortest paths are found. A priority queue efficiently supports this by quickly retrieving the minimum-distance node.