Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In the second part of the project, you need to implement BFS in JAVA. Your program should take as input a graph adjacency matrix as

image text in transcribed

"In the second part of the project, you need to implement BFS in JAVA. Your program should take as input a graph adjacency matrix as in DFS, and generate the following:

Order in which vertices are first encountered. Assume that the vertices are visited in numerical order when no other order is specified by the search.

The number of connected components in the graph.

Tree edges

Cross edges.

For the graph in Figure 1, the program should generate the following vertex ordering (count value for vertices): 1 2 5 6 7 3 8 4

The number of connected components is 1. The tree edges and cross edges are given by two adjacency matrices:

Tree edges

0 1 0 0 1 1 0 0

0 0 0 0 0 0 1 0

0 0 0 1 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 1 0 0 0 0 1

0 0 0 0 0 0 0 0

Cross edges

0 0 0 0 0 0 0 0

0 0 0 0 0 1 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 1 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 1 0 0 0 0"

I was able to create a BFS that gives the order in which the vertices are visited, but was not able to figure out how to program it to find the cross edges.

1 4 Figure 1: Example graph In the example graph shown in Figure 1, the input graph adjacency matrix is specified in a text file with the following content 1 0 0 0 0 1 1 0 0 0 0 1 0 01 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 1 0 01 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions