Single source Shortest path

Posted on April 24, 2015

Properties

Bellman-Ford algorithm

{% highlight C%} BELLMAN-FORD(G, w ,s) Initialize-single-source(G, s) //initializes every v.d to positive infinity for i = 1 to |G.V|-1 Relax(u,v,w) for each edge (u,v) in G.E if v.d > u.d + w(u,v) return FALSE return TRUE {% endhighlight %}

Single-source shortest paths in directed acyclic graphs

{% highlight C %} DAG-SHORTEST-PATH(G, w, s) topologically sort the vertices of G INITIALIZE-SINGLE-SOURCE(G,s) for each vertex u, taken in topologically sorted order for each vertex v in G.adj[u] RELAX(u,v,w) {% endhighlight %}

Dijkstra’s Algorithm

{% highlight C %} DIJKSTRA(G, W, s) INITIALIZE-SINGLE-SOURCE(G, s) S = empty-set Q = G.V while Q is not empty u = EXTRACT-MIN(Q) S = S union {u} for each vertex v in G.Adj[u] RELAX(u,v,w) {% endhighlight %}

Notes