Question: You will write a C program to process a graph using its adjacency matrix stored in a . txt file as the input ( a

You will write a C program to process a graph using its adjacency matrix stored in a .txt file as
the input (a sample file is provided). The program should read the graph and provide several
functionalities for interacting with the graph.
Input:
The adjacency matrix (denoted as A) for the graph will be stored in a .txt file, where rows and
columns represent vertices (numbered 1,2,3,...), and the values in the matrix represent the edge
weights. If aij=0, it means that there is no edge between the vertex i and j.
Requirements:
1. Command-line argument:
o The program should accept the filename of the .txt file containing the graph's
adjacency matrix as a command-line argument.
o Example usage: ./a4 example-graph.txt (the executable is named a4).
2. Menu of Options: Upon running the program, it should present the user with a menu of
options. The user should be able to type the number of an option, and the program should
execute the corresponding functionality.
Display Adjacency List
Perform Breadth-First Search (BFS)
Perform Depth-First Search (DFS)
Find Shortest Path using Dijkstra's Algorithm
Exit
3. Option Details:
o Option 1: Display Adjacency List
When this option is selected, the program should print the adjacency list
representation of the graph. Each vertex should list its connected vertices along
with weights of the edges.
o Option 2: Perform Breadth-First Search (BFS)
When this option is selected, the program should perform a Breadth-First Search
(BFS) traversal starting from vertex 1. The program should print the vertices in
the order they are visited.
o Option 3: Perform Depth-First Search (DFS)
When this option is selected, the program should perform a Depth-First Search
(DFS) traversal starting from vertex 1. The program should print the vertices in
the order they are visited.
o Option 4: Find Shortest Path (Dijkstra's Algorithm)
When this option is selected, the program should compute and print the shortest
paths from vertex 1 to all other vertices using Dijkstra's algorithm.
o Option 5: Exit
When this option is selected, the program should exit.
example-graph -
04500
40192
51003
09000
02300
sample output - Menu: 1. Display Adjacency List 2. Perform Breadth-First Search (BFS)3. Perform Depth-First Search (DFS)4. Find Shortest Path using Dijkstra's Algorithm 5. Exit Enter your choice: 1 Adjacency List: Vertex 1: ->2(4)->3(5) NULL Vertex 2: ->1(4)->3(1)->4(9)->5(2) NULL Vertex 3: ->1(5)->2(1)->5(3) NULL Vertex 4: ->2(9) NULL Vertex 5: ->2(2)->3(3) NULL Menu: 1. Display Adjacency List 2. Perform Breadth-First Search (BFS)3. Perform Depth-First Search (DFS)4. Find Shortest Path using Dijkstra's Algorithm 5. Exit Enter your choice: 2 Final BFS Order: 12345 Menu: 1. Display Adjacency List 2. Perform Breadth-First Search (BFS)3. Perform Depth-First Search (DFS)4. Find Shortest Path using Dijkstra's Algorithm 5. Exit Enter your choice: 312354 Menu: 1. Display Adjacency List 2. Perform Breadth-First Search (BFS)3. Perform Depth-First Search (DFS)4. Find Shortest Path using Dijkstra's Algorithm 5. Exit Enter your choice: 4 Shortest distance from vertex 1 to vertex 1: 0 Shortest distance from vertex 1 to vertex 2: 4 Shortest distance from vertex 1 to vertex 3: 5 Shortest distance from vertex 1 to vertex 4: 13 Shortest distance from vertex 1 to vertex 5: 6 Menu: 1. Display Adjacency List 2. Perform Breadth-First Search (BFS)3. Perform Depth-First Search (DFS)4. Find Shortest Path using Dijkstra's Algorithm 5. Exit Enter your choice: 5 Exiting...

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!