Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with calculating whether or not a graph is connected or not. As it stands now, I know all the code I have

I need help with calculating whether or not a graph is connected or not. As it stands now, I know all the code I have works, but I don't have the check for connectivity coded yet. It is supposed to throw a new IllegalArgumentException. I also know that the hasPathto code works, but I do not know how to implement it/how to get it to correctly figure out if something is marked. As it stand, a node is marked if it can be reached, and therefore is connected. My code:

image text in transcribed

// You need only change the constructor // You can also change the main method // But you should not change eccentricity), diameter, radius(), center) or iscenter) // You can (and should!) add more private methods (such as bfs or dfs) public class MyGraphPropertiesf int[] eccentricity; int diameter int radius; int center; boolean[] marked; // Constructor can be linear in G.VO G.E) public MyGraphProperties(Graph G)f this . eccentricity = new int[GV()]; int diameter = Integer.MIN VALUE; int radius = Integer.MAX VALUE; int center -1; marked ne boolean[GM)]; int s e; // If G.VC)-=e, then these are the correct values. I If G is not connected, you should throw a new // IllegalArgumentException) // I suggest that you first get it to work for a connected graph // This will require that you traverse the graph starting from some node // (say e) // You can then adjust your code so that it throws an exception in the // case that all nodes are not visited for (int v = 0; v eccentricity[v]) center = v; diameter eccentricity[v]; = radius eccentricity[v]; = this . diameter this . radius = this . center = = diameter; radius; center; private boolean hasPathTo(int v) f return marked v];) private int bfs (Graph G, int s) t Queue

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

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

Students also viewed these Databases questions