Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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 to n 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:
represents the graph:
Uploaded graph
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: 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 depthfirst search on the
graph using the pseudocode found on page in the textbook. In place of the PREVISITv line,
enqueue on to a previsit queue. In place of the POSTVISIT line, enqueue on to a postvisit queue.
The overall structure of your program should follow this pseudocode:
Read in the first line of input to get
Create an ajacency matrix A containing zeroes
Read in the second line of input to get
for to
Read in a line of input to get wertex numbers
Set to
Create a previsit queue
Create a postvisit queue
Call DFS
Print the contents of the previsit queue on a single line
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started