What’s Dijkstra’s Algorithm?
Dijkstra’s Algorithm is used for locating the shortest path between any two vertices of a graph. It makes use of a precedence queue for locating the shortest path. For extra element, about Dijkstra’s Algorithm, you’ll be able to confer with this article.
Why Dijkstra’s Algorithm makes use of a Precedence Queue?
We use min heap in Dijkstra’s Algorithm as a result of a node can have a number of weighted edges however for the shortest path, we have now to think about the smallest weighted edge related to a node. For this, we use a precedence queue (min-heap) which provides us the minimal factor on the highest of the precedence queue.
For the implementation of Dijkstra’s Algorithm utilizing Precedence Queue, you’ll be able to take a look at this GFG Article.
The Time Complexity of Dijkstra’s Algorithm is O((V+E)* logV), right here V = no. of nodes within the graph, E = no. of edges within the graph
Can we use a Queue as a substitute of a Precedence Queue?
The reply to this query is sure, we are able to use a queue as a substitute of Precedence Queue.
The one distinction between a queue and a precedence queue is that we have now to traverse all related nodes of a present node and discover the minimal amongst them after we use a traditional queue which takes time of O(V). However utilizing the precedence queue we are able to optimize it to O(log V).
The Time Complexity of Dijkstra’s Algorithm utilizing a regular queue is O(V2).