Repository link: https://github.com/CSE-116/ProblemSet-4
To submit your project, run problem.Zipper, which will create a zip file containing the
problem set, and submit it to Autolab.
For this problem set, you will complete public static methods in the problem.ProblemSet4 class. Each
method takes a Graph<T> and is generic over the node type T. The graph uses
only bidirectional edges (see Graph.addBidirectionalEdge). Method signatures appear in the starter
code.
countEdges (Testing: 5 points, Implementation: 5 points): In the problem.ProblemSet4
class, complete the countEdges method, which takes a Graph as a parameter and
returns an int. This method returns the number of edges in the input graph. Each undirected edge
between two distinct nodes counts once (the adjacency list stores each edge twice, once per endpoint)
maxDegree (Testing: 5 points, Implementation: 5 points): In the problem.ProblemSet4
class, complete the maxDegree method, which takes a Graph as a parameter and
returns an int. This method returns the maximum degree among all nodes (Degree of a node is the number of
neighbors of that node)
0
isConnected (Testing: 5 points, Implementation: 5 points): In the problem.ProblemSet4
class, complete the isConnected method, which takes a Graph as a parameter and
returns a boolean. This method returns true if the input graph is connected, and
false otherwise
numberOfConnectedComponents (Testing: 5 points, Implementation: 5 points): In the
problem.ProblemSet4 class, complete the numberOfConnectedComponents method, which
takes a Graph as a parameter and returns an int. This method returns the number of
connected components in the graph
0 components
0) is its own component
detectCycle (Testing: 5 points, Implementation: 5 points): In the problem.ProblemSet4
class, complete the detectCycle method, which takes a Graph as a parameter and
returns a boolean. This method returns true if the graph contains at least one
cycle, and false otherwise
true
Write tests for the methods in the specification
in the tests.TestProblemSet4 class. You are encouraged to write tests before you implement each
method. If a test fails, use the debugger to find and fix your bug.
countEdges
countEdges method. Test that the proper value is returned in a
variety of cases
Graph class to construct a graph. The number of times you call
addBidirectionalEdge should be the expected number of edges
Graph that takes a type
parameter. You may choose any type when you create your graphs (eg. Using whatever is simplest,
like Integer, is fine). Since nodes are stored as keys in a HashMap, your
Graph cannot contain duplicate node values
maxDegree
maxDegree method. Test that the proper value is returned in a
variety of cases
isConnected
isConnected method. Test that the proper value is returned in a
variety of cases
addNode method in the Graph class is public in this version of the
code in case you want to add nodes with no edges while creating disconnected graphs
numberOfConnectedComponents
numberOfConnectedComponents method. Test that the proper
value is returned in a variety of cases
addNode when you need isolated nodes
detectCycle
detectCycle method. Test that the proper value is returned in a
variety of cases
Implement the methods from the specification.
You are encouraged to complete the Testing Requirements before you begin implementation so you can run your tests as you implement each part.
With testing now being required, feedback from Autolab will be given in several phases.