Menu

[Solved]Given Adjacency List Representation Graph Write Function Generateadjmatrix Generates Retur Q37144758

Given the adjacency list representation of a graph, write a function generateAdjMatrix that generates and returns the adjaceninport java.util.LinkedList; public class Graph int numWertices LinkedList<Integer Graph(int n)i adjacencyList; numVerticesn

Please write comments

Given the adjacency list representation of a graph, write a function generateAdjMatrix that generates and returns the adjacency matrix representation of the graph based on the adjacency list. Write another function printMatrix that takes the adjacency matrix input and print it. For example: For the following graph: Input: Adjacency List: 2:0 3:2 4:3–1 Output: The adjacency Matrix: 01011 0010 e inport java.util.LinkedList; public class Graph int numWertices LinkedList<Integer Graph(int n)i adjacencyList; numVerticesn adjacencyList for(int -;i<numvertices;i++) adjacencyList[1] new LinkedList<Integer>(); void addEdge(Integer sre, Integer des) this.adjacencyList[src).add (des); void printGraphO for(int -; ithis.nutVertices;S++) //System.out.printin(“Adjacency 1ist of vertex+); System.out.print(” “+i+ int j-e; for( j<this.adjacencyList[].size)1;j+) System.out.print (this.adjacencyList[.getj)) Systen.out.print(.-)·); if(j adjacencyList.size)-1) System.out printin(this.adjacencyList[i].get(j)) else System.out.printin public static Integertt generateAdjMatrix) Integer[][] adjacencyMatrix = null; INSERT CODE HERE return adjacencyMatrix; public static void printMatrix (Integer] adjMatrix) INSERT CODE HERE public static void ain (Stringt args) // Create a graph of 5 vertices Graph g2 new Graph( 5); g2.addEdge(8, 1): g2.addEdge(8, 4): g2.addEdge(8, 3): g2.addEdge(2, 8): g2.addEdge(3, 2): g2.addEdge(4, 3): g2.addEdge(4, 1); g2.printGraph); Integer adjMatrix-generateAdjMatrix): printMatrix(adjMatrix); Should print the following Matrix 01811 8e8 e 0101 Show transcribed image text Given the adjacency list representation of a graph, write a function generateAdjMatrix that generates and returns the adjacency matrix representation of the graph based on the adjacency list. Write another function printMatrix that takes the adjacency matrix input and print it. For example: For the following graph: Input: Adjacency List: 2:0 3:2 4:3–1 Output: The adjacency Matrix: 01011 0010 e
inport java.util.LinkedList; public class Graph int numWertices LinkedList

Expert Answer


Answer to Given the adjacency list representation of a graph, write a function generateAdjMatrix that generates and returns the ad… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *