Question
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 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 0Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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