Question: Goal Design and code an algorithm to do a breadth first search on an undirected simple graph, finding the connected components and determining the shortest

 Goal Design and code an algorithm to do a breadth first
search on an undirected simple graph, finding the connected components and determining
the shortest distances within each component. Details Input to your program consists
of an integer n representing the number of vertices followed an adjacency

Goal Design and code an algorithm to do a breadth first search on an undirected simple graph, finding the connected components and determining the shortest distances within each component. Details Input to your program consists of an integer n representing the number of vertices followed an adjacency matrix of n rows, each row with n entries. Details of the format of the input are the same as for Lab 1 and Lab 2. Each entry of the n x n adjacency matrix, will contain a 1 if there is an edge between the corresponding vertices or a O if there is no edge Output the number of vertices and the matrix then use the iterative breadth first search algorithm, see slide 6 of the GraphTheoryAlgorithms slides, to traverse the graph and output the vertices of a component along with their distances. Once the BFS is finished, determine if the BFS has visited every vertex. If not, repeat the BFS finding the next component until all components have been output. Lastly, output the total number of components. Output format should be exactly the same as that given in the examples below EXAMPLE 1 ac Matrix Representation 00100 00100 11011 00101 00110 / 5 vertices in graph. There will be 5 rows of the matrix, each with 5 entries. // Row 1 of Adjacency Matrix, vertices adjacent to vertex 1 // Row 2 of Adjacency Matrix, vertices adjacent to vertex 2 //Row 3 of Adjacency Matrix, vertices adjacent to vertex 3 // Row 4 of Adjacency Matrix, vertices adjacent to vertex 4 //Row 5 of Adjacency Matrix, vertices adjacent to vertex 5 Output Number of Vertices: 5 Matrix: 00100 00100 11011 00101 00 110 Component 1: Vertices &Distances: 10

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!