Dijkstra Algorithm

Sources Authors

Dijkstra Algorithm

Information

How does Dijkstra works?

Graph

Import

Export

Vertex

Start End
Remove

Edge

Remove
Algorithm
 1  function Dijkstra(Graph, source):
 2
 3      create vertex set Q
 4
 5      for each vertex v in Graph:             // Initialization
 6           ← INFINITY                  // Unknown distance from source to v
 7           ← UNDEFINED                 // Previous node in optimal path from source
 8          add v to                           // All nodes initially in Q (unvisited nodes)
 9
10       ← 0                        // Distance from source to source
11
12      while  is not empty:
13           ← vertex in Q with min     // Source node will be selected first
14          remove  from 
15
16          for each neighbor  of :           // where v is still in Q.
17               + 
18              if  < dist[v]:               // A shorter path to v has been found
19                  
20                  
21
22      return dist[], prev[]
                            
 1  function Dijkstra(Graph, source):
 2
 3      create vertex set Q
 4
 5      for each vertex v in Graph:
 6           ← INFINITY
 7           ← UNDEFINED
 8          add v to 
 9
10       ← 0
11
12      while  is not empty:
13           ← vertex in Q with min 
14          remove  from 
15
16          for each neighbor  of :
17               + 
18              if  < dist[v]:
19                  
20                  
21
22      return dist[], prev[]
                            
slow
fast
Reset Next Run Stop
Variables
Path
{{v.name}}
There has no path been found yet!
Graph Clear Vertices
vertex predecessor distance from start
{{p.name}} {{p.prev}} {{p.dist}}
Vertices will be shown as soon as algorithm is running.