Create a public class GraphAnalysis
that provides a single static
method named isUndirected
.
isUndirected
accepts an UnweightedGraph<?>
from cs1.graphs
and should return true
if the graph is
undirected and false
otherwise.
If the passed graph is null
, throw an IllegalArgumentException
.
Each node in the graph has a set of neighbors that you can retrieve representing links from that node to other nodes. If the graph is undirected, if there is a link from A to B then there is also a link from B to A. So if B is a neighbor of A, then A should also be a neighbor of B.
Note that you do not need to solve this problem recursively, since there is a concise iterative solution.
For reference, cs1.graphs.UnweightedGraph
has the following public properties:
And cs1.graphs.GraphNode
has the following public properties:
You're challenge is to write tests for this problem described above.
Stuck? You may find these lessons helpful: