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


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: 01-4-3 4:3–1 Output: The adjacency Matrix: 010 1 1 10000 01010 Graph Class import java.util.LinkedList; public class Graph int numVertices; LinkedList<Integer> Graph(int n) adjacencyList; adjacencyList new LinkedListInumVerticesl; for(int i-0;inumVertices;i++) adjacencyList[i]-new LinkedList<Integer>); void addEdge (Integer src, Integer des) this.adjacencyList[src].add (des); void printGraph) for(int i-0; i<this.numVertices;i++) /System.out.println(“Adjacency list of vertex: 1); System.out.print(“”+i*”: “); int j-0; for(G j<this.adjacencyList[i].size()-1;j++) System.out.print (this.adjacencyList[i].get(j)) System.out.print(“”; if(j–adjacencyList[i].size)-1) System.out.println(this.adjacencyList[i].get(j)) else System.out.println); public static Integer[]] generateAdjMatrix)( Integer[][] adjacencyMatrix-null; / INSERT CODE HERE return adjacencyMatrix; public static void printMatrix(Integer[] adjMatrix)( / INSERT CODE HERE public static void main(String[] args) f // Create a graph of 5 vertices Graph g2-new Graph (5) g2. addEdge(, 1); g2. addEdge(e, 4); g2. addEdge(, 3); g2. addEdge(2, 0); 82. addEdge(3, 2); g2. addEdge(4, 3); g2.addEdge(4, 1); g2.printGraph () Integer[[] adjMatrix- generateAdjMatrix); printMatrix(adjMatrix); Should print the following Matrix 0 1 011 1888 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: 01-4-3 4:3–1 Output: The adjacency Matrix: 010 1 1 10000 01010
Graph Class import java.util.LinkedList; public class Graph int numVertices; LinkedList Graph(int n) adjacencyList; adjacencyList new LinkedListInumVerticesl; for(int i-0;inumVertices;i++) adjacencyList[i]-new LinkedList); void addEdge (Integer src, Integer des) this.adjacencyList[src].add (des); void printGraph) for(int i-0; i
Expert Answer
Answer to Given the adjacency list representation of a graph, write a function generateAdjMatrix that generates and returns the ad… . . .
OR

