felipernb/algorithms.js — pull request #34 by quietshu (2014-05-31 20:20:02+00:00)
Title: SPFA algorithm added

Add SPFA algorithm and tests :P

From Wikipedia:

[Shortest Path Faster Algorithm (SPFA)](http://en.wikipedia.org/wiki/SPFA) is an improvement of the Bellman–Ford algorithm which computes single-source shortest paths in a weighted directed graph.

procedure Shortest-Path-Faster-Algorithm(G, s)
1 for each vertex v ≠ s in V(G)
2 d(v) := ∞
3 d(s) := 0
4 offer s into Q
5 while Q is not empty
6 u := poll Q
7 for each edge (u, v) in E(G)
8 if d(u) + w(u, v) < d(v) then
9 d(v) := d(u) + w(u, v)
10 if v is not in Q then
11 offer v into Q