Given a graph and a source vertex, Dijkstra's finds shortest path to all other vertices.
Running time: O(N^2)
- Build adjacency matrix
- Create a visited array (initialized to false)
- Create a distance matrix (populated with distances to each vertex from source
- Initialize distance[source] = 0 and visited[source] = true
- While not all vertices have been visited yet, or loop V-1 times
a. Find the unvisited vertex with minimum distance to any of the visited vertices
b. Mark it as visited
c. Update the distance matrix with the distances from the newly added vertex: if distance[vertex] + adj[vertex][current] < distance[current], then update.
Given a graph and a source vertex, Dijkstra's finds shortest path to all other vertices.
Running time: O(N^2)
a. Find the unvisited vertex with minimum distance to any of the visited vertices
b. Mark it as visited
c. Update the distance matrix with the distances from the newly added vertex: if distance[vertex] + adj[vertex][current] < distance[current], then update.