2023 SPRING CS 445 LAB #8:
WRITING THE GRAPH CLASS
Background:
The Graph class you will write uses uses a 2D array of int as the backing data structure.
Be sure to read document linked at very bottom of this page.
This assignment was borrowed and converted from C++ to Java as needed by Tim Hoffman with permission from it's original author
Mark Stehlik
Here are the given files:
Development Strategy
- Finish the loadGraph() method. It is called from the constructor.
- Finish the toString() method. It is called from the Tester
- Run your Graph class against the TinyTester until everything works right.
- Once you are sure the TinyTester produces correct output start running your
Graph class against the real GraphTester.java and write/test one method at a time.
- WRITE AND TEST METHODS -ONE AT A TIME-
The degree of a vertex is the number of edges incident to that
vertex. For a directed graph, we can define the following terms:
- outDegree - the number of edges leaving the vertex
- inDegree - the number of edges entering the vertex
- degree - the number of edges entering and leaving
the vertex
You are to declare and implement private member functions for each of the above and
private method boolean hasEdge( int src, int dest)
-- T/F whether
there is an edge from src node to dest node
After doing so and testing your implementation, you are to implement the
following 7 public methods in your Graph.java file to exercise the 4 private member
functions above,
- maxOutDegree - the maximal number of edges leaving any
single vertex
- minOutDegree - the minimal number of edges leaving any
single vertex
- maxInDegree - the maximal number of edges entering any
single vertex
- minInDegree - the minimal number of edges entering any
single vertex
- maxDegree - the maximal number of edges entering/leaving any
single vertex
- minDegree - the minimal number of edges entering/leaving any
single vertex
- removeEdge - puts a NO_EDGE value into the matrix or throws an Exception if bad values were passed in
For our input file, graphdata.txt, the correct answers are:
- maxOutDegree - 3
- minOutDegree - 1
- maxInDegree - 4
- minInDegree - 0
- maxDegree - 5
- minDegree - 2
This page explains each method and how to write it: Graph Class