Connected Components of a Network (Graph) Not all networks are connected. For example, imagine an estate with many buildings, each of which has many rooms. If we model this estate with a network, then...


Connected Components of a Network (Graph)


Not all networks are connected. For example, imagine an estate with many buildings, each of which has many rooms. If we model this estate with a network, then the rooms within each building are accessible one to another, but not the rooms between two buildings.


Write a program that accepts a possibly disconnected network (represented by a two-dimensional array) and prints a list of rooms in each building. Number the buildings beginning with 1. This can be done recursively or iteratively.


For example, if the estate array is:


 0 1 0 0 1 0 0


 1 0 0 0 1 0 0


 0 0 0 1 0 1 1


 0 0 1 0 0 1 1


 1 1 0 0 0 0 0


 0 0 1 1 0 0 1


 0 0 1 1 0 1 0


your output should be:


 Building 1: Room numbers 0, 1, 4.


 Building 2: Room numbers 2, 3, 6, 5.

Nov 16, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here