Question: Implement the methods maxDegree() and numConnectedComponents() in the graph implementation. See comments on top of method for what each method does. import java.util.LinkedList; import java.util.List;
Implement the methods maxDegree() and numConnectedComponents() in the graph implementation. See comments on top of method for what each method does. import java.util.LinkedList; import java.util.List; public class Graph { protected List vertices = new LinkedList<>(); protected class Vertex { protected T data; protected List adjacencies = new LinkedList<>(); protected boolean visited; public Vertex(T data) { this.data = data; vertices.add(this); } public T getData() { return data; } } /* This function computes the maximum degree over all the vertices * returnsL integer : max degree over all vertices */ public int maxDegree() { int maxDegree = 0; CODE HERE return maxDegree; } /* Determines the number of connectedd components in a graph * A connected component is a maximum part of a graph where all * vertices are connected. For examle, a connected graph of size * would have 1 connected component, and a graph of size n with * no edges would have n componentds * * returns: the number of connected components */ public int numConnectedComponents() { int numComponents = 0; // You may need a helper function //CODE HERE return numComponents; } // Placeholder for helper function // CODE HERE public Vertex addVertex(T data) { return new Vertex(data); } public void addEdge(Vertex u, Vertex v) { v.adjacencies.add(u); u.adjacencies.add(v); } }Step by Step Solution
3.42 Rating (146 Votes )
There are 3 Steps involved in it
To implement the maxDegree and numConnectedComponents methods in the Graph class you need to conside... View full answer
Get step-by-step solutions from verified subject matter experts
