Question: l import java.io.*; 2 import java.util.*; 4/ Epublic abstract class GraphUtils ( 6 static Graph empty Graph ) return new AdjSetGraph ); String dumpGraph (Graph

 l import java.io.*; 2 import java.util.*; 4/ Epublic abstract class GraphUtils

( 6 static Graph empty Graph ) return new AdjSetGraph); String dumpGraph

(Graph g) { 10 static "Vertex count _ " + g.vertexCount() +

" "; String s for (Vv : g.ve rtices()) { 12 13

l import java.io.*; 2 import java.util.*; 4/ Epublic abstract class GraphUtils ( 6 static Graph empty Graph ) return new AdjSetGraph); String dumpGraph (Graph g) { 10 static "Vertex count _ " + g.vertexCount() + " "; String s for (Vv : g.ve rtices()) { 12 13 14 15 16 17 18 19 20 for (V w g.neighbors (v)) return s; 21 AdjSetGraph.java 1 Epublic class GraphTest ( 3 public static void main (String argv[]) throws Exception { Graph g = Graphutils.emptyGraph(); g.addVertex (10) g.addVertex (20) g.addVertex (30) g.addEdge (10,20); g.addEdge (10, 30) g. addEdge (20, 30) : system.out.println("Stage 1:"); system.out.print (GraphUtils. dumpGraph (g)); System.out.println ("Graph contains vertex 10: "g.hasVertex (1O)); System.out.println("Graph contains vertex 50: " + g.hasVertex (50)); System.out.println ("Degree of vertex 10 g.degree (10)) System.out.println("Degree of vertex 30 g.degree (30)) g.addVertex (30) ; g.addVertex(40) g.addEdge (10,40); g.addEdge (10,30) g.addVertex (50): System.out.printin ("SLage 2:") System.out.print (GraphUtils.dumpGraph (g)): System.out.println ("Graph contains vertex 10: " g.hasVertex (10)): System.out.println("Graph contains vertex 50: g.hasVertex (So)): System.out.println ("Degree of vertex 10g.degree (10)) 6 12 14 20 23 24 25 27 System.out.println ("Degree of vertex 30"+ g.degree (30)) Java source file 1 // Abstract Data Type for undirected graphs with vertices of type V // Self-loops are allowed, but parallel edges are not interface Graph { 61 Add a vertex. No-op if vertex already exists. void addVertex (V v) 9/ Return all the vertices Iterable vertices; 12I Return the number of vertices. 13 | int vertexCountDa 14 // Answer whether a particular vertex is in the graph boolean hasVertex (V v); 1E 18 1 Add an edge between two vertices. 19 19 Raises IllegalArgumentException if either vertex is not in graph 20 / No-op if edge already exists 21 void addEdge (V vl,V v2) 23 24 25 26 / Return the neighbors of a vertex // Raises IllegalArgumentException if vertex is not in graph Iterable neighbors (V v): // Return the degree (number of neighbors) of a vertex // Raises IllegalrgumentException if vertex is not in graph 28 29 30 31 32 int degree (V v) 34 l import java.io.*; 2 import java.util.*; 4/ Epublic abstract class GraphUtils ( 6 static Graph empty Graph ) return new AdjSetGraph); String dumpGraph (Graph g) { 10 static "Vertex count _ " + g.vertexCount() + " "; String s for (Vv : g.ve rtices()) { 12 13 14 15 16 17 18 19 20 for (V w g.neighbors (v)) return s; 21 AdjSetGraph.java 1 Epublic class GraphTest ( 3 public static void main (String argv[]) throws Exception { Graph g = Graphutils.emptyGraph(); g.addVertex (10) g.addVertex (20) g.addVertex (30) g.addEdge (10,20); g.addEdge (10, 30) g. addEdge (20, 30) : system.out.println("Stage 1:"); system.out.print (GraphUtils. dumpGraph (g)); System.out.println ("Graph contains vertex 10: "g.hasVertex (1O)); System.out.println("Graph contains vertex 50: " + g.hasVertex (50)); System.out.println ("Degree of vertex 10 g.degree (10)) System.out.println("Degree of vertex 30 g.degree (30)) g.addVertex (30) ; g.addVertex(40) g.addEdge (10,40); g.addEdge (10,30) g.addVertex (50): System.out.printin ("SLage 2:") System.out.print (GraphUtils.dumpGraph (g)): System.out.println ("Graph contains vertex 10: " g.hasVertex (10)): System.out.println("Graph contains vertex 50: g.hasVertex (So)): System.out.println ("Degree of vertex 10g.degree (10)) 6 12 14 20 23 24 25 27 System.out.println ("Degree of vertex 30"+ g.degree (30)) Java source file 1 // Abstract Data Type for undirected graphs with vertices of type V // Self-loops are allowed, but parallel edges are not interface Graph { 61 Add a vertex. No-op if vertex already exists. void addVertex (V v) 9/ Return all the vertices Iterable vertices; 12I Return the number of vertices. 13 | int vertexCountDa 14 // Answer whether a particular vertex is in the graph boolean hasVertex (V v); 1E 18 1 Add an edge between two vertices. 19 19 Raises IllegalArgumentException if either vertex is not in graph 20 / No-op if edge already exists 21 void addEdge (V vl,V v2) 23 24 25 26 / Return the neighbors of a vertex // Raises IllegalArgumentException if vertex is not in graph Iterable neighbors (V v): // Return the degree (number of neighbors) of a vertex // Raises IllegalrgumentException if vertex is not in graph 28 29 30 31 32 int degree (V v) 34

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!