
CPSC 212-301 Name: _____________________________
Test #3A November 30, 2005
Honor Pledge:
I pledge that I have neither given nor received unauthorized assistance on this test.
Signed: _______________________ Date: _____________
20 points. 50 minutes. Open Java API. Open cucs API. You may not visit any other web page. You are to
develop a class called MyGraph with one constructor:
public MyGraph (int [][] M) {
// ... your code ...
} // MyGraph
which receives an int M[][] x which is an adjacency matrix representation of graph G. Note that if M[i]
[j] = w > 0, then there exists an edge from node i to node j with weight w. You may assume that the
matrix is correct (i.e., no need for input error checking). You should write five methods, summarized
below:
public boolean isWeighted(){ public boolean isDirected() {
// … returns true if graph // … returns true if graph is
// is weighted, else false // a directed graph, else false
} // isWeighted } // delete
public int outdegree(int x) { public int indegree(int x) {
// returns outdegree of node x // returns indegree of node x
} // outdegree } // indegree
public String dfs (int x) {
// … returns the order in which nodes are visited in a pre-order depth-
// first search of the graph starting with node x. This method may
// not be recursive.
} // dfs
Submission:
Submit your work using: handin.212.301 3 MyGraph.java
Also submit any helper methods and/or classes you developed during this test and required by your class.
Important:
If you cannot complete one or more of the methods, be sure to include a skeleton of the method which
returns a value (boolean or String) prints the String:
“Method ___________ not completed”
so that my test driver will be able to compile your program.
Evaluation:
Your program will be evaluated on: (a) correctness of algorithm, and (b) efficiency of algorithm.