This is a program in C that works with graphs. It reads a graph from a file and represents it as an adjacency list. The program provides a menu-driven interface that allows users to interact with the graph in several ways. Users can display the graph as an adjacency list, perform Breadth-First Search (BFS) or Depth-First Search (DFS) to explore its structure, and use Dijkstra's algorithm to find the shortest path from a starting vertex to all other vertices.
- Graph Theory: Understanding graph representations (Adjacency Matrix, Adjacency List).
- Algorithm Implementation: Breadth-First Search (BFS), Depth-First Search (DFS), and Dijkstra's Algorithm.
- File Handling: Reading a graph from a file.
- Memory Management: Efficiently using dynamic memory in C (linked lists).
- Command-Line Arguments: Using arguments to pass file names.
The program performs the following:
- Reads a graph's adjacency matrix from a
.txtfile. - Provides options to display the graph's adjacency list, perform BFS, DFS, and find the shortest path using Dijkstra’s algorithm.
- Ensures robust file handling, input validation, and proper memory management.
- Display Adjacency List: Convert the adjacency matrix into an adjacency list and display the list for all vertices.
- Breadth-First Search (BFS): Traverse the graph using BFS starting from vertex 1.
- Depth-First Search (DFS): Traverse the graph using DFS starting from vertex 1.
- Dijkstra’s Algorithm: Compute and display the shortest path from vertex 1 to all other vertices using Dijkstra’s algorithm.
- Exit: Quit the program.
The program continues showing the menu after performing an action until the user selects the "Exit" option. Memory is cleaned up before quitting.
The project consists of the following files:
- graph.h: Header file containing function declarations and data structure definitions.
- main.c: The main program that handles the menu, reads the graph from the file, and calls the appropriate functions.
- graph_functions.c: File containing the implementations of the graph-related functions (e.g., BFS, DFS, Dijkstra, adjacency list creation).
- Makefile: Makefile for compiling your program.
- README.md: A brief explanation of the project and instructions for compiling and running it.
To compile and run the program, follow these steps:
- In the directory where the files are saved, type: make
This will compile all necessary files into an executable.