Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 3(30p) The figure below shows the structure of a directed graph. Answer the questions based on it. class Vertex class Edge { {
Question 3(30p) The figure below shows the structure of a directed graph. Answer the questions based on it. class Vertex class Edge { { }; public int vertexId; public Vertex nextVertex; public Edge edgeLink; graph 1 2 3 m m 2 4 +36/ 2 7 DE 1 2 2 5 }; public int vertexld; public int weight; public Edge nextEdge; edge. Starting vertex is 1, ending vertex is 3 Public Graph copyGraph()//copies the graph Public void restore Graph(Graph g) // restores the graph Public int count() // returns the number of vertices in the graph. Public void topologicalSort(){...} vertex a) Write a method in Graph class that find the neighbors of a given vertex id.(10p) b) Write a method that will do topological sort(display vertex ids. You do not have keep them) on the graph. Your method will be in the Graph class. The following methods are implemented for you to use incase you need them. (20p) Public Vertex findVertexIndegreeZero()//finds and return a vertex with an indegree of zero Public bool checkCycle() // checks whether the graph has a cycle or not
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres an implementation of the requested methods in the Graph class java import javautil public class Graph private Vertex vertices private int numVer...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started