DEPARTMENT OF COMPUTER SCIENCE
AND ENGINEERING
DATA STRUCTURES AND ALGORITHMS FOR
PROBLEM SOLVING(MCS103)
TOPIC: BELLMANFORD ALGORITHM
PRESENTED BY: GUIDED BY:
RAGHAVI CS 1KS24SCS05 DR. VIJAYALAXMI MEKALI
ASSOCIATE PROFESSOR,
K S INTITUTE OF
TECHNOLOGY
KANAKAPURA ROAD,
BENGALORE
INDEX(TABLE OF
CONTENTS)
• Introduction
• Algorithm steps
• Scenario and C program code
• Tree model representation
• Conclusion
INTRODUCTI
ON
The Bellman-Ford Algorithm finds the shortest path from a single source to
all other vertices in a weighted graph. Unlike Dijkstra’s algorithm, it can
handle negative weight edges.
Key Features:
Works with both positive and negative weights.
Runs in O(V × E) time complexity, where V is the number of vertices and E is
the number of edges.
Uses relaxation to progressively update the shortest path estimates.
Algorithm
steps
How It Works:
Initialize distances from the source to all vertices as infinity (∞), except for the
source itself, which is set to 0.
Relax all edges (V-1) times, where V is the number of vertices.
Perform an extra iteration to check for negative weight cycles. If further
relaxation is possible, a negative weight cycle exists.
Scenario and C program code
• A flight booking system needs to find the cheapest flight route between NYC to
Miami cities. Each route has a different ticket price (edge weight). Edge
representation and path detection .
Graph representation or tree model
representation
• (NYC) NYC-> New York City
/ \
300 200
/ \
(LA)------(Chicago) LA-> Las Angels
\ / |
150 100 250
\ / |
(Dallas)----(Miami)
C
program
•.
Output
Conclusi
on
• The Bellman-Ford algorithm is a powerful and flexible single-source
shortest path algorithm that works even for graphs with negative weight
edges
THANK YOU