This project implements three core graph algorithms using pure Python:
- Dijkstra's Algorithm – for finding the shortest paths from a source node.
- Kruskal's Algorithm – for computing a Minimum Spanning Tree (MST).
- DFS with Topological Sort and Cycle Detection – for analyzing directed graphs.
. ├── inputs/ → Graph input files (auto-generated) ├── outputs/ → Algorithm results written here ├── graph_generator_custom.py → Generates random graphs with/without cycles ├── graph_solver_custom.py → Runs selected algorithm on input graphs └── README.txt → This file
✓ Requires Python 3.6+ ✓ No external libraries needed
Run: python graph create.py
This creates 10 graphs:
- 5 Undirected (for Kruskal and Dijkstra)
- 5 Directed (some cyclic, some acyclic for DFS/Topo)
Each graph file includes:
- Comment lines for metadata
- Number of vertices, edges, and graph type
- List of edges with weights
- A source node (used by Dijkstra)
Run: python main.py
You will be prompted to choose one of the options:
1. Dijkstra (SSSP)
2. Kruskal (MST)
3. DFS Topological Sort / Cycle Detection
The script will:
- Pick 5 valid input graphs randomly
- Run the selected algorithm
- Save results to the 'outputs/' folder
- Uses only Python’s built-in libraries (os, random, collections)
- Algorithms provide: • Paths and costs (Dijkstra) • MST edges and total cost (Kruskal) • Topological order or all cycles (DFS)
18 35 U A B 5 B C 2 ... A
MST Edges: A - B : 3 C - D : 2 ...
Total MST cost: 106
TEJASWI
None. Uses only:
- os
- random
- collections