Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Topics covered: Graphs, BFS, BFT, diameter, connected components The topology of a network is modeled with a graph. Write a C++ program that inputs a

image text in transcribedimage text in transcribed

Topics covered: Graphs, BFS, BFT, diameter, connected components The topology of a network is modeled with a graph. Write a C++ program that inputs a graph G by first inputting the number of vertices n followed by a sequence of pairs i j where i and j are integers between 0 and n, inclusive, representing the edges of the graph, and ending with a negative integer sentinel to indicate the end of the input. For example, 5 0 1 1 42 3 1 3 3 4-1 represents the graph G (V.E) given by: V 0,1,2,3,4) E-0,11,4),(2,33,11,3),13,4)) Your program will compute the diameter of G in the case when G is connected and the connected components of G, otherwise. You can proceed as follows: Implement the graph G with its adjacency matrix Implement the function BFS (G, v) for performing a breadth-first search where the visit operation involves computing the distance from v to the vertex being visited. This will require a queue, which you can get from the Standard Template Library (STL) * Implement a function Diameter (G) that returns the diameter of G if G is connected and -1, otherwise. Implement a function Components (G) for computing the vertex sets of the connected components of G. Components () will employ a BFT (Breadth-First Traversal), which involves calling BFS (G, v), v-0,1,.. n -1, as discussed in class. * Store the entire source code for your program in a single file. Your program should run using Visual C++ Have your program output the adjacency matrix of the graph as well as the diameter in the case when G is connected and the connected components, otherwise. Output the connected components by outputting the vertex set of each connected component. Run your program for each of the two cases, G connected and G disconnected, for a graph of your choosing and attach a hard copy of this output after your source code. Your program should be user-friendly, well-commented, with the output well- documented

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

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions

Question

Question 1 (a2) What is the reaction force Dx in [N]?

Answered: 1 week ago

Question

explain the concept of strategy formulation

Answered: 1 week ago