What does relaxation of an edge
mean in the context of graph theory ? I came across this while studying up on Dijkstra's algorithm for single source shortest path.

- 26,489
- 43
- 149
- 227
8 Answers
Here's a nice description of the Algorithm that also explains the notion of relaxation.
The notion of "relaxation" comes from an analogy between the estimate of the shortest path and the length of a helical tension spring, which is not designed for compression. Initially, the cost of the shortest path is an overestimate, likened to a stretched out spring. As shorter paths are found, the estimated cost is lowered, and the spring is relaxed. Eventually, the shortest path, if one exists, is found and the spring has been relaxed to its resting length.
-
2Is there a reason for telling that the EDGE is relaxed, and not the path to the node v. Why "EDGE" relaxation and not "PATH" relaxation – user3245268 Dec 03 '18 at 04:47
-
4Makes little sense this explanation. Are springs the edges? Then what happens to other springs when one is relaxed? Why aren't they all relaxed at the beginning? Or are springs shortest paths? Then they are not compressible beyond what? Why to talk about "relaxing springs" and not "shortening cords"? I've heard that "relaxation" comes from Operations Research, but i cannot yet figure out details... – Alexey Feb 12 '20 at 17:15
The relaxation process in Dijkstra's algorithm refers to updating the cost of all vertices connected to a vertex v, if those costs would be improved by including the path via v.

- 2,552
- 19
- 23
-
1This doesn't answer the question, which is about what it means to relax an *edge*. – Jun 16 '21 at 20:52
Relaxing an edge, (a concept you can find in other shortest-path algorithms as well) is trying to lower the cost of getting to a vertex by using another vertex.
You are calculating the distances from a beginning vertex, say S, to all the other vertices. At some point, you have intermediate results -- current estimates. The relaxation is the process where you check, for some vertices u and v:
if directly_connected(v, u)
if est(S, v) > est(S, u) + dist(u,v)
est(S, v) = est(S, u) + dist(u, v)
where est(S,a)
is the current estimate of the distance, and dist(a,b)
is the distance between two vertices that are neighbors in the graph.
What you are basically checking in the relaxation process is weather your current estimate from a to b could be improved by "diverting" the path through c (this "diversion" would be the length of a path from a to c and from c to b).

- 8,251
- 8
- 45
- 87
Edge relaxation process
Initialization
In shortest-path algorithms, a high cost tells the algorithm "do not go down that path". So by default, we only know that the starting node is apart of the shortest path, while all other nodes are still undetermined. Therefore, we assign a low cost of zero to the starting node (e.g. S), and a high cost of infinity to every other node (e.g. A, E).
S := new Node()
A := new Node()
E := new Node()
// low cost
S.edge_cost = 0
// high cost
A.edge_cost = 1000 // "infinity"
E.edge_cost = 1000 // "infinity"
Relaxation
The high costs are only temporary, and we now need to "relax" reduce the costs. To do that, we use the edge costs (e.g. a, b, and c), and update the nodes if they are lower.
// Check if S node can be reduced
// SS := S.edge_cost + S.edge_cost // 0 + 0 = 0
// if (S.edge_cost > SS) { // 0 > 0 => false
// S.edge_cost = SS
// }
// Check if A node can be reduced
SA := S.edge_cost + a // 0 + 3 = 3
if (A.edge_cost > SA) { // 1000 > 3 => true
A.edge_cost = SA // 3
}
// Check if E node can be reduced
AE := A.edge_cost + b // 3 + 5 = 8
if (E.edge_cost > AE) { // 1000 > 8 => true
E.edge_cost = AE // 8
}
Relaxation repeated
// Note: The nodes hold memory,
// so the `edge_cost` remembers the previous cost,
// and that's what the edge is compared against
SE := S.edge_cost + c // 0 + 1 = 1
if (E.edge_cost > SE) { // 8 > 1 => true
E.edge_cost = SE // 1
}

- 16,217
- 5
- 62
- 51
-
This seems to be defining what it means to relax a vertex, but it doesn't define what it means to relax an edge. – Jun 16 '21 at 20:58
-
@user1142217 - The edges are SA, SE, and AE. As the vertices A and E are relaxed down from infinity, so are the edges. – tim-montague Oct 12 '22 at 22:39
I can't comment yet but let me have a go at answering the comments on the accepted answer.
user3245268 commented:
Is there a reason for telling that the EDGE is relaxed, and not the path to the node v. Why "EDGE" relaxation and not "PATH" relaxation
The reason why typically edges are relaxed as opposed to paths might be that during the execution of Dijkstra's algorithm, no explicit representation of any path is present; all you have at this stage are the predecessor pointers of each node.
Obviously, if an edge is relaxed, the implicit new shortest path is relaxed as well, so it does not contradict the analogy to relax a path. But in the algorithm, where you don't really think about paths yet, the notion of relaxing an edge on the path instead makes just as much sense in the context.
Alexey commented:
Makes little sense this explanation. Are springs the edges? Then what happens to other springs when one is relaxed? Why aren't they all relaxed at the beginning? Or are springs shortest paths? Then they are not compressible beyond what? Why to talk about "relaxing springs" and not "shortening cords"? I've heard that "relaxation" comes from Operations Research, but i cannot yet figure out details...
Yes, springs are the edges.
When one spring is relaxed, some "tension" in part of the subgraph may be released and some other springs may relax as well as a result.
At the beginning, the (preliminary) shortest distance from the starting node to any other node is initialized to infinity, so all springs are streched out to infinity.
The springs are supposed to be "not compressible [beyond their resting state]," but I do think that this is rather confusing, and that the alternative "cord model" of a graph is a bit simpler to grasp. Cords can
- be streched to their proper length
- be overstreched beyond their proper length while they are not explored yet or
- just dangle about when they are not part of any shortest path
When relaxing an edge, the edge of the "new shortest path" goes from overstreched to just streched, while the edge of the "old shortest path" goes from streched to loose.

- 11
- 1
lets suppose in graph if we have (u,v)∈ E where w(u,v)=10 then if by adding a third vertex in between them like w(u,y)=1 and w(y,v)=3 now we find a path between u and v with weight 1+3=4<10. Now we will consider the second path as shortest which is (u,y,v) and will ignore the first one, this is relaxation.

- 1
- 1
Edge relaxation.
To relax an edge v -> w means to test whether the best-known way from s to w is to from s to v, then take the edge from v to w, and, if so, update our data structures.
Java code:
private void relax(DirectedEdge e) {
int v = e.from(), w = e.to;
if (distTo[w] > distTo[v] + e.weight()) {
distTo[w] = distTo[v] + e.weight();
edgeTo[w] = e;
}
}
There is also vertex relaxation. That means to relax all the edges pointing from a given vertex.
private void relax(EdgeWeightedGraph G, int v) {
for (DirectedEdge e : G.adj(v)) {
relax(e);
}
}

- 949
- 8
- 6
-
1This is not especially clear, but at least, unlike the previous answers, it makes an attempt to answer the question about what it means to relax an *edge*. – Jun 16 '21 at 20:54
Take a look at https://www.youtube.com/watch?v=2E7MmKv0Y24&t=1336s Time: 28:30. Funny thing is that the shortest paths are the ones that are under TENSION. To me this is the exact opposite of RELAX. Oh well.

- 179
- 1
- 2
- 5