CPSC 212-301 Test 3A - MyGraph Class Implementation, Exams of Algorithms and Programming

Instructions for a university computer science exam focusing on the implementation of a mygraph class in java. Students are required to write a constructor and five methods for a weighted, undirected graph. The methods include checking graph properties (isweighted, isdirected), calculating node degrees (outdegree, indegree), and performing a depth-first search (dfs). The document also includes submission instructions and evaluation criteria.

Typology: Exams

Pre 2010

Uploaded on 07/28/2009

koofers-user-3eb
koofers-user-3eb 🇺🇸

9 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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.

Partial preview of the text

Download CPSC 212-301 Test 3A - MyGraph Class Implementation and more Exams Algorithms and Programming in PDF only on Docsity!

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.