CSC301: Homework [1/9] Previous pageContentsNext page

Read through section 4.2 of the text.

For homework, complete the following, using only Graph and GraphGenerator from algs41. You may copy code from other classes in algs41, but you should not use the classes themselves.

In particular, you may not use BreadthFirstPaths although you may copy code from there.

The eccentricity of a vertex v is the length of the shortest path from that vertex to the furthest vertex from v. The diameter of a graph is the maximum eccentricity of any vertex. The radius of a graph is the smallest eccentricity of any vertex. A center is a vertex whose eccentricity is the radius. Implement the following API. (See the starter code on D2L.)

public class MyGraphProperties {
  // constructor (exception if G not connected)
  MyGraphProperties(Graph G) {

  // eccentricity of v
  int eccentricity(int v) {  }

  // diameter of G
  int diameter() {  }

  //  radius of G
  int radius() {  }

  // a center of G --- any one will do
  int center() {  }

Previous pageContentsNext page