






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The shortest path problem in graph theory, focusing on the single source shortest paths problem, negative weights, and the Bellman-Ford algorithm. It covers the concepts of weighted graphs, shortest path weights, breadth-first search, and Dijkstra's algorithm. The document also explains the effects of negative weights and negative weight cycles on shortest path weights and provides an overview of the Bellman-Ford algorithm.
Typology: Summaries
1 / 11
This page cannot be seen from the preview
Don't miss anything!







Single Source Shortest Paths Introduction: In a shortest- paths problem , we are given a weighted, directed graphs G = (V, E), with weight function w: E โ R mapping edges to real-valued weights. The weight of path p = (v 0 ,v 1 ,..... vk) is the total of the weights of its constituent edges: We define the shortest - path weight from u to v by ฮด(u,v) = min (w (p): uโv), if there is a path from u to v, and ฮด(u,v)= โ, otherwise. The shortest path from vertex s to vertex t is then defined as any path p with weight w (p) = ฮด(s,t). The breadth-first- search algorithm is the shortest path algorithm that works on unweighted graphs, that is, graphs in which each edge can be considered to have unit weight. In a Single Source Shortest Paths Problem , we are given a Graph G = (V, E), we want to find the shortest path from a given source vertex s โ V to every vertex v โ V. Variants: There are some variants of the shortest path problem.
Example:
3. Upper-bound property: We always have d[v] โฅ ฮด(s, v) for all vertices v โ V, and once d[v] conclude the value ฮด(s, v), it never changes. 4. No-path property: If there is no path from s to v, then we regularly have d[v] = ฮด(s, v) = โ. 5. Convergence property: If s->u->v is a shortest path in G for some u, v โ V, and if d[u] = ฮด(s, u) at any time prior to relaxing edge (u, v), then d[v] = ฮด(s, v) at all times thereafter. Relaxation The single - source shortest paths are based on a technique known as relaxation , a method that repeatedly decreases an upper bound on the actual shortest path weight of each vertex until the upper bound equivalent the shortest - path weight. For each vertex v โ V, we maintain an attribute d [v], which is an upper bound on the weight of the shortest path from source s to v. We call d [v] the shortest path estimate. INITIALIZE - SINGLE - SOURCE (G, s) 1. for each vertex v โ V [G] 2. do d [v] โ โ 3. ฯ [v] โ NIL 4. d [s] โ 0 After initialization, ฯ [v] = NIL for all v โ V, d [v] = 0 for v = s, and d [v] = โ for v โ V - {s}. The development of relaxing an edge (u, v) consists of testing whether we can improve the shortest path to v found so far by going through u and if so, updating d [v] and ฯ [v]. A relaxation step may decrease the value of the shortest
(b) Here, v. d < u. d + w (u, v) before relaxing the edge, and so the relaxation step leaves v. d unchanged. The subsequent code performs a relaxation step on edge (u, v) RELAX (u, v, w)
Step 3: Now find the adjacent of y that is t, x, z.
Then d [x] โ 13 ฯ [x] โ z Case - (ii) z โ s d [v] > d [u] + w [u, v] d [s] > d [z] + w [z, s] 0 > 7 + 7 0 > 14 โด This condition does not satisfy so it will be discarded. Now we have x = 13. Step 5: Now we will find Adj [t] Adj [t] โ [x, y] [Here t is u and x and y are v] Case - (i) t โ x d [v] > d [u] + w [u, v] d [x] > d [t] + w [t, x] 13 > 8 + 1 13 > 9 Then d [x] โ 9 ฯ [x] โ t Case - (ii) t โ y d [v] > d [u] + w [u, v] d [y] > d [t] + w [t, y] 5 > 10 โด This condition does not satisfy so it will be discarded. Thus we get all shortest path vertex as Weight from s to y is 5 Weight from s to z is 7 Weight from s to t is 8 Weight from s to x is 9 These are the shortest distance from the source's' in the given graph.
Solution: distk^ [u] = [min[distk-^1 [u],min[distk-^1 [i]+cost [i,u]]] as i โ u. dist^2 [2]=min[dist^1 [2],min[dist^1 [1]+cost[1,2],dist^1 [3]+cost[3,2],dist^1 [4]+cost[4,2],dist^1 [5]+cost[5,2]]] Min = [6, 0 + 6, 5 + (-2), โ + โ , โ +โ] = 3 dist^2 [3]=min[dist^1 [3],min[dist^1 [1]+cost[1,3],dist^1 [2]+cost[2,3],dist^1 [4]+cost[4,3],dist^1 [5]+cost[5,3]]] Min = [5, 0 +โ, 6 +โ, โ + โ , โ + โ] = 5 dist^2 [4]=min[dist^1 [4],min[dist^1 [1]+cost[1,4],dist^1 [2]+cost[2,4],dist^1 [3]+cost[3,4],dist^1 [5]+cost[5,4]]] Min = [โ, 0 +โ, 6 + (-1), 5 + 4, โ +โ] = 5 dist^2 [5]=min[dist^1 [5],min[dist^1 [1]+cost[1,5],dist^1 [2]+cost[2,5],dist^1 [3]+cost[3,5],dist^1 [4]+cost[4,5]]] Min = [โ, 0 + โ,6 + โ,5 + 3, โ + 3] = 8 dist^3 [2]=min[dist^2 [2],min[dist^2 [1]+cost[1,2],dist^2 [3]+cost[3,2],dist^2 [4]+cost[4,2],dist^2 [5]+cost[5,2]]] Min = [3, 0 + 6, 5 + (-2), 5 + โ , 8 + โ ] = 3 dist^3 [3]=min[dist^2 [3],min[dist^2 [1]+cost[1,3],dist^2 [2]+cost[2,3],dist^2 [4]+cost[4,3],dist^2 [5]+cost[5,3]]] Min = [5, 0 + โ, 3 + โ, 5 + โ,8 + โ ] = 5 dist^3 [4]=min[dist^2 [4],min[dist^2 [1]+cost[1,4],dist^2 [2]+cost[2,4],dist^2 [3]+cost[3,4],dist^2 [5]+cost[5,4]]] Min = [5, 0 + โ, 3 + (-1), 5 + 4, 8 + โ ] = 2 dist^3 [5]=min[dist^2 [5],min[dist^2 [1]+cost[1,5],dist^2 [2]+cost[2,5],dist^2 [3]+cost[3,5],dist^2 [4]+cost[4,5]]] Min = [8, 0 + โ, 3 + โ, 5 + 3, 5 + 3] = 8
dist^4 [2]=min[dist^3 [2],min[dist^3 [1]+cost[1,2],dist^3 [3]+cost[3,2],dist^3 [4]+cost[4,2],dist^3 [5]+cost[5,2]]] Min = [3, 0 + 6, 5 + (-2), 2 + โ, 8 + โ ] = dist^4 [3]=min[dist^3 [3],min[dist^3 [1]+cost[1,3],dist^3 [2]+cost[2,3],dist^3 [4]+cost[4,3],dist^3 [5]+cost[5,3]]] Min = 5, 0 + โ, 3 + โ, 2 + โ, 8 + โ ] = dist^4 [4]=min[dist^3 [4],min[dist^3 [1]+cost[1,4],dist^3 [2]+cost[2,4],dist^3 [3]+cost[3,4],dist^3 [5]+cost[5,4]]] Min = [2, 0 + โ, 3 + (-1), 5 + 4, 8 + โ ] = 2 dist^4 [5]=min[dist^3 [5],min[dist^3 [1]+cost[1,5],dist^3 [2]+cost[2,5],dist^3 [3]+cost[3,5],dist^3 [5]+cost[4,5]]] Min = [8, 0 +โ, 3 + โ, 8, 5] = 5