? Graph.java that implements a directed graph using an adjacency matrix. /** * This file gives the implementation of a Graph. * * YOUR TASKS : Implement methods (1) multiplyMatrix and (2) getNeighbors of the class Graph. */ import java.util.Arrays; public class Graph { /** * This class implements a directed graph, representing it using an adjacency matrix. * */ private char[] vertices; private int[][] adjacencyMatrix; public Graph(char[] vertices){ int numVertices = vertices.length; this.vertices = vertices; adjacencyMatrix = new int[numVertices][numVertices]; } public void addEdge(char from,

»? Graph.java that implements a directed graph using an adjacency matrix. /** * This file gives the implementation of a Graph. * * YOUR TASKS : Implement methods (1) multiplyMatrix and (2) getNeighbors of the class Graph. */ import java.util.Arrays; public class Graph { /** * This class implements a directed graph, representing it using an adjacency matrix. * */ private char[] vertices; private int[][] adjacencyMatrix; public Graph(char[] vertices){ int numVertices = vertices.length; this.vertices = vertices; adjacencyMatrix = new int[numVertices][numVertices]; } public void addEdge(char from, char to){ /** * Adds an edge (from, to) to the graph creating a path from vertex ‘from’ to vertex ‘to’. */ adjacencyMatrix[new String(vertices).indexOf(from)][new String(vertices).indexOf(to)] = 1; } public void removeEdge(char from, char to){ /** * Removes the edge (from, to) from the graph. */ adjacencyMatrix[new String(vertices).indexOf(from)][new String(vertices).indexOf(to)] = 0; } public static int[][] multiplyMatrix(int[][] matrixA, int[][] matrixB){ /** * Multiplies 2 two-dimensional matrices, that it takes as argument, and returns the resulting matrix. * * YOUR TASK: Write the appropriate code to multiply matrixA and matrixB, store the result in matrix result, * and return matrix result at the end. * */ int[][] result = ; /** * WRITE YOUR CODE HERE */ return result; } public String[] getNeighbors(int distance){ /** * For every vertex in the graph, identifies and returns the list of vertices at a distance ‘distance’ from it * * YOUR TASK: Write the appropriate code that will (i) for every vertex, find the list of vertices a the distance * passed as argument from it, and (2) return the lists of ‘neighbors’ as an array of String; the neighbors for a * vertex is returned as a comma-separated String (a comma separating the label of each neighbor for the vertex). * * For example, if there are 3 vertices A, B and C, and distance = 2. It will identify the vertices with a path of * length 2 from vertex A. It will do the same for vertices B and C. Suppose that there are the following paths * of length 2 in the graph: A to B, A to C, B to C and C to A. The function will then return {“B, C”, “C”, “A}. * */ String[] neighborList = new String[vertices.length]; Arrays.fill(neighborList, “”); // initialize all elements with empty string /** * WRITE YOUR CODE HERE */ return neighborList; } public String toString(){ int numVertices = vertices.length; String tmp = “Vertices: “; for(char vertex: vertices) { tmp += vertex + “t”; } tmp += “nEdges: “; for(int i = 0; i for(int j = 0; j if(adjacencyMatrix[i][j] == 1) { tmp += “(” + vertices[i] + “, ” + vertices[j] + “)t”; } } } return tmp; } } //end class Graph ? GraphApplicaiton.java with a main method that (i) creates a graph, (ii) displays its details, and, (iii) for every vertex, prints the list of vertices that are at a particular distance from it by calling method getNeighbors (distance is measured in terms of number of edges). * Main class of the Java program. * */ public class Main { public static void main(String[] args) { // we print a heading and make it bigger using HTML formatting System.out.println(” — Graph — “); // create a Graph object, print its details, and call method getNeighbors to find, for every vertex, the list // of vertices at a distance ‘pathLength’ from it (distance is im terms of number of edges) char[] vertices = {‘A’, ‘B’, ‘C’, ‘D’, ‘E’}; Graph myGraph = new Graph(vertices); myGraph.addEdge(‘A’, ‘B’); myGraph.addEdge(‘A’, ‘E’); myGraph.addEdge(‘B’, ‘D’); myGraph.addEdge(‘C’, ‘B’); myGraph.addEdge(‘D’, ‘A’); myGraph.addEdge(‘E’, ‘B’); myGraph.addEdge(‘E’, ‘C’); System.out.println(“Graph details:-“); System.out.println(myGraph); System.out.println(); int pathLength = 4; String[] neighborList = myGraph.getNeighbors(pathLength); System.out.println(“For each vertex, the list of vertices at distance ” + pathLength + ” from it:-“); for(int i = 0; i System.out.println(vertices[i] + “: ” + neighborList[i]); } } // end main } You are required to implement the following methods of class Graph: (i) multiplyMatrix that takes 2 two-dimensional matrices as argument, multiplies them, and returns the resulting matrix, and ii) getNeighbors which takes as arguments a distance, d, and, for every vertex, finds and returns a list of vertices that are d edges away from it as an array of Strings; the neighbors for a vertex is returned as a comma-separated String (a comma separating the label of each neighbor for the vertex). Note: A vertex can have an edge to itself, and there may be more than 1 path of length d between two vertices, e.g., 2 in the adjacency matrix for paths of length d implies that there are two such paths between the corresponding vertices. [7 marks]

»

The price is based on these factors:

Academic level

Number of pages

Urgency

Basic features

- Free title page and bibliography
- Unlimited revisions
- Plagiarism-free guarantee
- Money-back guarantee
- 24/7 support

On-demand options

- Writer’s samples
- Part-by-part delivery
- Overnight delivery
- Copies of used sources
- Expert Proofreading

Paper format

- 275 words per page
- 12 pt Arial/Times New Roman
- Double line spacing
- Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Delivering a high-quality product at a reasonable price is not enough anymore.

That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more