Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please provide examples. Graph.java provided below public class Graph { public i

ID: 3702007 • Letter: P

Question

Please provide examples. Graph.java provided below

public class Graph {
public int V;
public int E;
  
public LinkedList<Integer>[] adj;
  
public Graph()
{
V = 0;
E = 0;
}
  
public Graph(BufferedReader reader) throws IOException
{
String line;
line = reader.readLine();
V = Integer.parseInt(line);
line = reader.readLine();
E = Integer.parseInt(line);
adj = new LinkedList[V];
for (int v = 0; v < V; v++) {
adj[v] = new LinkedList<Integer>();
}
while ((line = reader.readLine()) != null) {
int tempV1, tempV2;
StringTokenizer st = new StringTokenizer(line, " ");
tempV1 = Integer.parseInt(st.nextToken());
tempV2 = Integer.parseInt(st.nextToken());
addEdge(tempV1, tempV2);
}
}
  
  
public void addEdge(int v, int w) {

}
  
public String tostring()
{
String s = new String();
s = "There are "+V+" vertices and "+E+" edges ";
for(int i=0;i<V;i++)
{
s = s+i+": ";
for(int j = 0; j<adj[i].size();j++)
{
s = s+adj[i].get(j)+" ";
}
s = s+" ";
  
}
return s;
}
  
}

1. Implement a weighted graph class from the Graph.java used previously. Graph.java uses integer value for storing an edge. Instead of using integer value for storing edges, create an "Edge" class that holds information of edge. Edge class has following attributes (not limited to): Vertex v1, v2 int edgelD int edgeWeight 2. Change the adjacency list to hold the vertex and edge weight. . Write a driver program, which reads input files mediumGraph.txt, LargeGraph.txt and XtraLargeGraph.tt (on Canvas) and display the weighted graphs by printing adjacency list.

Explanation / Answer

Answer :

1)

public class Edge {

private int edgeID;
private int edgeWeight;
private Vertex vertex1;
private Vertex vertex2;
  
public Edge() {
super();
}
  
public Edge(int edgeID, int edgeWeight, Vertex vertex1, Vertex vertex2) {
super();
this.edgeID = edgeID;
this.edgeWeight = edgeWeight;
this.vertex1 = vertex1;
this.vertex2 = vertex2;
}

public int getEdgeID() {
return edgeID;
}
  
public void setEdgeID(int edgeID) {
this.edgeID = edgeID;
}
  
public int getEdgeWeight() {
return edgeWeight;
}
  
public void setEdgeWeight(int edgeWeight) {
this.edgeWeight = edgeWeight;
}
  
public Vertex getVertex1() {
return vertex1;
}
  
public void setVertex1(Vertex vertex1) {
this.vertex1 = vertex1;
}
  
public Vertex getVertex2() {
return vertex2;
}
  
public void setVertex2(Vertex vertex2) {
this.vertex2 = vertex2;
}
  
@Override
public String toString() {
return "Edge [edgeID=" + edgeID + ", edgeWeight=" + edgeWeight + ", vertex1=" + vertex1 + ", vertex2=" + vertex2
+ "]";
}
}

class Vertex {
  
private int vertexID;
  
public Vertex(int vertexID) {
this.vertexID = vertexID;
}
  
public int getVertexID() {
return this.vertexID;
}
  
public void setVertexID(int vertexID) {
this.vertexID = vertexID;
}
}

--------------------------------------------------------------------------------------------------------------------

import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;

class Graph {
  
/* Adjacency List
*
* Edge will contain both vertices
* */
Map<Vertex, List<Edge>> adjacencyList = new HashMap<>();

......

......

......
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote