Question: 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

 Need help on Graph.c. I will be really appreciate it. ThanksFile Formats The input file will be in two parts. The firstpart will begin with a line consisting of a single integer ngiving the number of vertices in the graph. Each subsequent line willrepresent an edge by a pair of distinct numbers in the range

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

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 Databases Questions!