Question: Depth first search ( 1 5 points ) You are given a file that represents an undirected graph. The first two lines contain n ,

Depth first search (15 points)
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 m lines, 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:
(Uploaded graph)
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: (uploaded image)
Notes:
The program must take as a command line parameter the name of the input file.
The program must contain a method called DFS
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.represents the graph:
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 of input to get n
Create an nn ajacency matrix A containing zeroes
Read in the second line of input to get m
for i=1 to n
Read in a line of input to get wertex 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
 Depth first search (15 points) You are given a file that

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!