Answer:
Explanation:
Create a min-heap of size v (the number of vertices), each of which contains the vertex number and the distance from the root vertex (which is the source vertex).
So, the distance on the root vertex would be 0. And let the distances on all other nodes be infinite(since they will be updated later).
Until the min-heap gets empty, do the following
(i) Extract that vertex from the min-heap, which has the minimum distance value, using Extract-Min operation, which takes O(logV). Lets name it u
(ii) Now, for every adjacent vertex of u, say v, check if v is in min-heap or not. If yes, and if the distance value of u plus the edge weight u-v is less than the distance value of v, then update the distance value of v.
Running time of O(ElogV) is obtained, as the Extract-Min operation which takes O(logV), is performed at most E times, i.e. the number of edges times.