Understanding edge relaxation for shortest path algorithm

Created At: 2024-02-04 06:25:33 Updated At: 2024-02-14 12:30:47

In the sense of Dijkstra's or Bellman Ford's algorithm edge relaxation property is the core. Understanding edge relaxation plays vital role in understanding the shortest path algorithms along with graph theory.

d[v] = min{ d[v], d[u] + c(u, v) } 

The above is the mathematical representation of the edge relaxation. We may simply break down with a pseudo code

if ( d[u] + c(u, v) < d[v] ) then

d[v] = d[u] + c(u, v)

Now, I know from the first glance, the mathematical model or the code do not make any sense. Let's dig deep into them.

Here's the representation

  1. d stands for distance 
  2. v stands for a node
  3. u stands for a node
  4. d[u] stands for distance of u to itself
  5. d[v] stands for distance of v to itself
  6. c(u, v) stands for distance from u to v node

Initially we also introduce an initial node and we name with s. You may also replace u, v based on your nodes' names.

The mathematical model or the pseudo code is used to find the minimum distance between two nodes.

Here we will introduce the following based

  1. d(s) 
  2. d(u)
  3. d(v)

Here S is the initial node or vertex and the distance to itself is 0, so d(s) is equals to 0. And then other nodes we set do infinity d(u) and d(v) to .

Now let's set up some random values for the edges. 

Here we have introduced some randoms values to the edges. So let's calculate the cost to reach to U from S. This is also called relaxing U node. We will use the mathematical formula for that.

Steps and value

  1. d(s) is 0
  2. d(u) is 
  3. c(s, u) is 5

So if use the mathematical formula 

d[s] + c(s, u) < d[u] 

0+5 <

So if use pseudo code or the formula the value for d(u) is 5. And then for other two nodes we can find the values. Let's ee the current changes and nodes

So currently d(u) is 5. Now we would be able to calculate d(v) from d(s). We will use the the same mathematical formula and this time we are relaxing node V.

Steps and value

  1. d(u) is 4
  2. d(v) is
  3. c(u, v) is 5

d[u] + c(u, v) < d[v] 

5+4 < 

Here d(u) is 5(already calculated) and c(u, v) is 4 which is the weight value. Now the value of d(v) is 9. So this from S to V through U node

Now we will go to V node from S node directly. Here we already see weight value is 11. Let's calculate using the formula

Steps and value

  1. d(s) is 0
  2. d(v) is
  3. c(s, v) is 11

d[s] + c(s, v) < d[v] 

0+11 <

Now we have another d(v) value which is 11. Now this value directly from S to V. We also have earlier value of d(v) which is 9, this come from going through V node.

So finally we can say that we can use edge relaxation theory could solve dijkstra's algorithm.


Add Reviews

Latest Posts

Subscribe our newsletter