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 to n This is followed by mlines, where each line contains two integers representing an edge between those
vertices.
For example, a file with the lines:
represents the graph: follow image
Write a program that builds a graph from the input file and then carries out a depthfirst search on the graph using the pseudocode found on page in the textbook. In place of the PREVISITv line, enqueue v on to a previsit queue. In place of the POSTVISITv 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 to m
Read in a line of input to get vertex numbers uv
set Auv to
Create a previsit queue
Create a postvisit queue
Call DFS
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
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
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
