This repository contains Python implementations of three fundamental graph algorithms: Dijkstra's algorithm, Bellman-Ford algorithm, and Floyd-Warshall algorithm. These algorithms are tested with example graphs and can be easily extended for other test cases.
-
Dijkstra's Algorithm
- Finds the shortest path from a source vertex to all other vertices in a graph.
- Requires non-negative edge weights.
- Efficiently implemented using a priority queue.
-
Bellman-Ford Algorithm
- Finds the shortest path from a source vertex to all other vertices in a graph.
- Supports graphs with negative edge weights.
- Detects negative weight cycles and raises an exception if one is found.
-
Floyd-Warshall Algorithm
- Computes shortest paths between all pairs of vertices.
- Supports graphs with negative edge weights.
- Does not work with negative weight cycles.
dijkstra.py: Contains the implementation of Dijkstra's algorithm.bellman_ford.py: Contains the implementation of the Bellman-Ford algorithm.floyd_warshall.py: Contains the implementation of the Floyd-Warshall algorithm.
- Clone the repository:
git clone https://github.com/your-username/graph-algorithms.git cd graph-algorithms```
- Run the code:
python filename.py