WeBeginners-Community / DocBook

Documentations of Html to every open source technologies. It's a low-code repository
30 stars 54 forks source link

Bellman Ford Algorithm #154

Closed shailja2727 closed 1 year ago

shailja2727 commented 1 year ago

Description

It is an algorithm for directed graph.It is a single source shortest path algorithm. Dijkstra doesn’t work for Graphs with negative weights, Bellman-Ford works for such graphs.

Steps:

Step 1:

Let the given source vertex be 0. Initialize all distances as infinite, except the distance to the source itself. Total number of vertices in the graph is V, so all edges must be processed |V-1| times.

Step 2:

Relax all edges |V| - 1 times. A simple shortest path from src to any other vertex can have at-most |V| - 1 edges

Step 3:

Check for negative-weight cycles. The above step guarantees shortest distances if graph doesn't contain negative weight cycle.

Fixes:

Issue Number: #152

Type of change

N.A.

Checklist:

ATTACH SCREEN-SHOTS / DEPLOYMENT LINK

image