Question: Use edge lists to reimplement the Graph class from Figure 14.3 on page 744. There should be no limit to the number of vertices. Also

Use edge lists to reimplement the Graph class from Figure 14.3 on page 744. There should be no limit to the number of vertices. Also provide a new method that returns the edge list of a specified vertex.

FIGURE 14.3 Specification and Implementation of the Graph Class Generic Class Graph * public class Graph from the package edu.colorado.graphs A Graph is a labeled graph with a fixed number of vertices and labels of type E. Specification Constructor for the Graph public Graph(int n) Initialize a Graph with n

FIGURE 14.3 Specification and Implementation of the Graph Class Generic Class Graph

* public class Graph from the package edu.colorado.graphs A Graph is a

labeled graph with a fixed number of vertices and labels of type

E. Specification Constructor for the Graph public Graph(int n) Initialize a Graph

FIGURE 14.3 Specification and Implementation of the Graph Class Generic Class Graph * public class Graph from the package edu.colorado.graphs A Graph is a labeled graph with a fixed number of vertices and labels of type E. Specification Constructor for the Graph public Graph(int n) Initialize a Graph with n vertices, no edges, and null labels. Parameter: n- the number of vertices for this Graph Precondition: n >= 0. Postcondition: This Graph has n vertices, numbered from 0 to n-1. It has no edges and all vertex labels are null. Throws: OutofMemoryError Indicates insufficient memory to create this Graph. Throws: NegativeArraySizeException Indicates that n is negative. addEdge, isE dge, and removeEdge public void addEdge (int source, int target) public boolean isEdge(int source, int target) public void removeEdge (int source, int target) Add an edge, test whether an edge exists, or remove an edge of this Graph. Parameters: source - the vertex number of the source of the edge target the vertex number of the target of the edge Precondition: Both source and target are non-negative and less than size( ). Postcondition: For addEdge, the specified edge is added to this Graph (unless it was already present); for isEdge, the retum value is true if the specified edge ex ists and is false otherwise; and for removeEdge, the specified edge is removed from this Graph (unless it was already not present). Throws: ArrayIndexOutofBoundsException Indicates that the source or target was not a valid vertex number.

Step by Step Solution

3.49 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres a Python implementation of a Graph class using edge li... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Data Structures and Other Objects Using Java Questions!