The Owl Club of Cape Town, South Africa, a dining club, has its first formal meeting.
SPFA 72A
The Shortest Path Faster Algorithm (SPFA) is an improvement of the Bellman–Ford algorithm that computes single-source shortest paths in a weighted directed graph. The algorithm is believed[by whom?] to work well on random sparse graphs and is particularly suitable for graphs that contain negative-weight edges.[1] However, the worst-case complexity of SPFA is the same as that of Bellman–Ford, so for graphs with nonnegative edge weights Dijkstra's algorithm is preferred. SPFA was first published by Edward F. Moore in 1959, as a generalization of breadth first search;[2] SPFA is Moore's “Algorithm D.” The name, “Shortest Path Faster Algorithm (SPFA),” was given by Fanding Duan, a Chinese researcher who rediscovered the algorithm in 1994.[3]
Algorithm[edit]
Given a weighted directed graph �=(�,�)
and a source vertex �
, SPFA finds the shortest path from �
to each vertex �
, in the graph. The length of the shortest path from �
to �
is stored in �(�)
for each vertex �
.
The basic idea of SPFA is the same as the Bellman-Ford algorithm in that each vertex is used as a candidate to relax its adjacent vertices. The improvement over the latter is that instead of trying all vertices blindly, SPFA maintains a queue of candidate vertices and adds a vertex to the queue only if that vertex is relaxed. This process repeats until no more vertices can be relaxed.
Below is the pseudo-code of the algorithm.[4] Here �
is a first-in, first-out queue of candidate vertices, and �(�,�)
is the edge weight of (�,�)
.
A demo of SPFA based on Euclidean distance. Red lines are the shortest path covering (so far observed). Blue lines indicate where relaxing happens, i.e., connecting �
with a node �
in �
, which gives a shorter path from the source to �
.
procedure Shortest-Path-Faster-Algorithm(
G, s)
1 for each vertex v ≠ s in V(G)
2 d(v) := ∞
3 d(s) := 0
4 push s into Q
5 while Q is not empty do
6 u := poll Q
7 for each edge (u, v) in E(G) do
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 push v into Q
BenQ APAC Business Line Manager
1moSo beautiful ❤️