Implement the methods maxDegree() and numConnectedComponents() in the graph implementation. See comments on top of method for
Fantastic news! We've Found the answer you've been seeking!
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; 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); } }
Related Book For
Statistics Unlocking The Power Of Data
ISBN: 9780470601877
1st Edition
Authors: Robin H. Lock, Patti Frazer Lock, Kari Lock Morgan, Eric F. Lock, Dennis F. Lock
Posted Date: