1.0 - Negative-Weight Graphs

1.1 - Graphs without Negative Weight Edges

Let

pn=v1v2v3vn p_n=v_1\rightarrow v_2\rightarrow v_3\rightarrow \cdots\rightarrow v_n

be any shortest path from v1v_1 to vnv_n in a weighted graph with no negative weight edges

For all viv1,v2,,vn1v_i\in v_1, v_2, \cdots, v_{n-1}, we must have that the path prefix

pi=v1v2v3vi p_i=v_1\rightarrow v_2\rightarrow v_3\rightarrow\cdots\rightarrow v_i

is a shortest path from v1v_1 to viv_i and weight(pi)weight(pn)\text{weight}(p_i)\le\text{weight}(p_n)

distance(v1,vi)distance(v1,vn)\text{distance}(v_1, v_i)\le \text{distance}(v_1, v_n)

1.2 - Graphs with Negative-Weight Edges

1.3 - Bellman-Ford Solution

🌱 Shortest paths (of length of at least V1V-1) with negative edge weights of length nn can be found after relaxing all vertices n1n-1 times (regardless of order of edge relaxations)

1.4 - Bellman-Ford Algorithm

bellman_ford(G, w, s) // G is the graph, w is the weight function, s is the source vertex init_single_source(G, s) // Relax each edge V - 1 times to find shortest paths for i = 1 to |G.V| - 1 for each edge (u, v) ∈ G.E Relax(u, v, w) // Check for negative-weighte cycles reachable from s for each edge (u, v) ∈ G.E // If the relaxation condition is met, a negative-weight cycle // is detected if v.d > u.d + w(u, v) // Negative-weight cycle detected return false return true

1.4.1 - Bellman Ford Algorithm Analysis

are specialisations of a priority-first search

PriorityFirstSearch(G, s, ...) init_single_source(G, s) Q = G.V while Q != ∅ u = extract_min(Q) for each vertex v in G.adj[u] relax(u, v, ...) init_single_source(G, s) for each vertex v in G.V v.key = infinity v.pi = nil s.key = 0 relax(u, v, ...) if v.key > PRIORITY v.key = PRIORITY v.pi = u

At the end, the priority-first search tree is a minimum spanning tree.

1.5.3 - Dijkstra’s Algorithm

At the end, the priority-first search tree is a shortest-path tree