Question: You are given a file that represents an undirected graph. The first two lines contain n , the number of vertices, and m , the

You are given a file that represents an undirected graph. The first two lines contain n, the number of vertices, and m, the number of edges. Assume that the vertices are numbered from 0 to n 1. This is followed by mlines, where each line contains two integers representing an edge between those
vertices.
For example, a file with the lines:
5
6
01
02
13
14
24
34
represents the graph: [follow image]
Write a program that builds a graph from the input file and then carries out a depth-first search on the graph using the pseudocode found on page 226 in the textbook. In place of the PREVISIT(v) line, enqueue v on to a previsit queue. In place of the POSTVISIT(v) line, enqueue v on to a postvisit queue.
The overall structure of your program should follow this pseudocode:
Read in the first line if input to get n
Create an nxn ajacency matrix A containing zeros
Read in the second line of input to get m
for i=1 to m
Read in a line of input to get vertex numbers u,v
set A[u][v] to 1
Create a previsit queue
Create a postvisit queue
Call DFS(1)
Print the contents of the previsit queue on a single line
Print the contents of the postvisit queue on a single line
Your program must meet these requirements:
- The file must be named either DFSTest.java or DFSTest.py.
- Your name must appear in a comment at the top of program.
- The program must contain a method called DFS.
- It must also contain a main section, which is described above. For Java, that would be the main
method. For Python, that would be code at the bottom of the program at column 1.
- The program must take as a command line parameter the name of the input file.
- The program will print a line with your name, a line with the contents of the previsit queue, and a line with the contents of the postvisit queue.
-For Python programs, your code must be written so that I can run it using the command line
command:
python DFSTest.py filename
 You are given a file that represents an undirected graph. The

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!