# Edge Leisure Property for Dijkstra’s Algorithm and Bellman Ford’s Algorithm

Within the subject of graph idea, varied shortest path algorithms particularly ** Dijkstra’s algorithm** and

**repeatedly make use of using the approach known as**

__Bellmann-Ford’s algorithm__**Edge Leisure.**

The concept of rest is similar in each algorithms and it’s by understanding, the ‘** Leisure property**‘ we are able to absolutely grasp the working of the 2 algorithms.

**Leisure:**

The Edge Leisure property is outlined because the operation of enjoyable an edge u → v by checking whether or not the best-known means from S(supply) to v is to go from S → v or by going by way of the sting u → v. If it’s the latter case we replace the trail to this minimal price.

Initially, the reaching price from S to v is ready infinite(∞) and the price of reaching from S to S is zero.

Representing the price of a relaxed edge v mathematically,

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

And the fundamental algorithm for Leisure can be :

if

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

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

the place d[u] represents the reaching price from S to u

d[v] represents the reaching price from S to v

c(u, v) represents reaching price from u to v

## Fixing Single Supply Shortest Path downside by Edge Leisure methodology

- In single-source shortest paths issues, we have to discover all of the shortest paths from one beginning vertex to all different vertices. It’s by enjoyable an edge we take a look at whether or not we are able to enhance this shortest path(through the grasping method methodology).
- Which means that throughout traversing the graph and discovering the shortest path to the ultimate node, we replace the prices of the paths we’ve for the already recognized nodes as quickly as we discover a shorter path to achieve it.
- The beneath instance, will clear and absolutely clarify the working of the Leisure property.
- The given determine reveals graph G and we’ve to seek out the minimal price to achieve B from supply S.

**Enter**: graph – G

*Let A be u and B be v.*

The gap from supply to the supply can be 0.

=> d[S] = 0

Additionally, initially, the gap between different vertices and S can be infinite.

__INITIALIZE – SINGLE SOURCE PATH (G, S)__

for every vertex v within the graph

d[v] = ∞

d[S] = 0

### Now we begin enjoyable A.

The shortest path from vertex S to vertex A is a single path ‘S → A’.

d[u] = ∞

As a result of, d[S] + c(S, u) < d[u]

d[u] = d[S] + c(S, u) = 0 + 20

=> d[u] = 20

### Now we loosen up vertex B.

The method stays the identical the one distinction we observe is that there are two paths resulting in B.

The trail I: ‘S→B’

Path II: ‘S→A→B’First, take into account going by way of the trail I – d[v] = ∞

As a result of, d[S] + c(S, v) < d[v]

d[v] = d[S] + c(S, v) = 0 + 40

=> d[v] = 40Since its a decrease worth than the earlier initialized d[v] is up to date to 40, however we are going to now proceed to checking path II as per the grasping methodology method.

d[v] = 40

As a result of, d[u] + c(u, v) < d[v]

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

=> d[v] = 30

For the reason that new d[v] has a decrease price than the earlier of case I we once more replace it to the brand new obtained by taking path II. We can’t replace the d worth to any decrease than this, so we end the sting rest.

Finally we get the minimal price to achieve one another vertices within the graph from the supply and therefore fixing the only supply shortest path downside.

Lastly, we are able to conclude that** **the algorithms for the shortest path issues (Dijkstra’s Algorithm and Bellman-Ford Algorithm) could be solved by repeatedly utilizing** edge rest.**