Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help on Graph.c. I will be really appreciate it. Thanks File Formats The input file will be in two parts. The first part will

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Need help on Graph.c. I will be really appreciate it. Thanks

File Formats The input file will be in two parts. The first part will begin with a line consisting of a single integer n giving the number of vertices in the graph. Each subsequent line will represent an edge by a pair of distinct numbers in the range 1 to n, separated by a space. These numbers are the end vertices of the corresponding edge. The first part of the input file defines the graph, and will be terminated by a dummy line containing "O 0". After these lines are read your program will print the adjacency list representation of the graph to the output file. For instance, the lines below define the graph pictured above, and cause the above adjacency list representation to be printed. 1 2 2 6 3 4 4 5 5 6 The second part of the input file will consist of a number of lines, each consisting of a pair of integers in the range 1 to n, separated by a space. Each line specifies a pair of vertices in the graph; a starting point (or source) and a destination. The second part of the input file will also be terminated by the dummy line "O 0". For each source-destination pair your program will do the following: Perform a Breadth First Search (BFS) from the given source vertex. This assigns a parent vertex (which may be nil) to every vertex in the graph. The BFS algorithm will be discussed in class and is described in general terms below. The pseudo-code for BFS can be found in section 22.2 of the text. e Use the results of BFS to print out the distance from the source vertex to the destination vertex, then use the parent pointers to print out a shortest path from source to destination. (See the algorithm Print- Path in section 22.2 of the text.) File Formats The input file will be in two parts. The first part will begin with a line consisting of a single integer n giving the number of vertices in the graph. Each subsequent line will represent an edge by a pair of distinct numbers in the range 1 to n, separated by a space. These numbers are the end vertices of the corresponding edge. The first part of the input file defines the graph, and will be terminated by a dummy line containing "O 0". After these lines are read your program will print the adjacency list representation of the graph to the output file. For instance, the lines below define the graph pictured above, and cause the above adjacency list representation to be printed. 1 2 2 6 3 4 4 5 5 6 The second part of the input file will consist of a number of lines, each consisting of a pair of integers in the range 1 to n, separated by a space. Each line specifies a pair of vertices in the graph; a starting point (or source) and a destination. The second part of the input file will also be terminated by the dummy line "O 0". For each source-destination pair your program will do the following: Perform a Breadth First Search (BFS) from the given source vertex. This assigns a parent vertex (which may be nil) to every vertex in the graph. The BFS algorithm will be discussed in class and is described in general terms below. The pseudo-code for BFS can be found in section 22.2 of the text. e Use the results of BFS to print out the distance from the source vertex to the destination vertex, then use the parent pointers to print out a shortest path from source to destination. (See the algorithm Print- Path in section 22.2 of the text.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

using signal flow graph

Answered: 1 week ago