Answered step by step
Verified Expert Solution
Link Copied!

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 (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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

Write a single linked list program and explain briefly

Answered: 1 week ago