Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

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

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions