Question 3(30p) The figure below shows the structure of a directed graph. Answer the questions based...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
Answer Method to find neighbors of a given vertex id public List Integer findNeighborsint vertexId List Integer neighbors new ArrayList Vertex vertex verticesvertexId Assuming vertices is an array of ... View the full answer
Related Book For
Physics
ISBN: 978-0077339685
2nd edition
Authors: Alan Giambattista, Betty Richardson, Robert Richardson
Posted Date:
Students also viewed these programming questions
-
An appropriate structure for large-scale distributed systems is as multiple, independently administered, firewall-protected, domains. Examples are a national health service, a national police service...
-
The Apache NetBeans IDE is mainly composed of NetBeans Open-Source IDE and NetBeans Platform. (True/False)
-
While serving as the president of the Federal Reserve Bank of St. Louis, William Poole stated, "Although my own preference is for zero inflation properly managed, I believe that a central bank...
-
For a first-order model with three variables, the variance of the predicted response at the design center (in coded units) is /2, if an unreplicated 23 design is used to collect the experimental...
-
Describe the role of an organizations personnel in compliance and antifraud efforts.
-
Love All is a fairly large manufacturing company located in the southern United States. The company manufactures tennis rackets, tennis balls, tennis clothing, and tennis shoes, all bearing the...
-
Introduction : provide the reader a bulleted list of all the points your will discuss in the presentation. Database Management Systems: identify some basic concepts associated with database...
-
Branson Co. received its bank statement for the month ending May 31, 2022, and reconciled the statement balance to the May 31, 2022, balance in the Cash account. The reconciled balance was determined...
-
What is displayed when the following program is executed. s = 'Hello World' for k in range(len(s)): if k%2 == 0: print(s[k],end = ")
-
Measure the length and diameter of the cylindrical specimen and the diameter of the spherical specimen using the ruler and the Vernier caliper. Record these data in Table 2. The Micrometer Caliper...
-
2: What was the largest" Change in assets and liabilities" in the operating section of the cash flow statement? Explain the direction of its effect in the reconciliation. 3: Examine American Eagle...
-
Oriole, Inc. manufactures soy candles in the Southeast region of the United States. The company has reported the following costs for its rose-scented line of candles: Glass Containers, $32000; Cotton...
-
(b) Find the state-transition matrix (t, 7) associated with a homogenous LTI system with # where A = T T = 11 11 - 20 00 1 0 - 31 T-, #
-
Mr. and Mrs. Clegg adopted a child in the current year. During the year, the Cleggs' qualified adoption expenses were $15,000, and they had an AGI of $70,000. What is the Cleggs' Adoption Credit for...
-
A company has the following inventory policy: inventory is observed and when this is 2 less, 2 products are ordered. If inventory is 3 more products, it is not ordered. The probability of having 0...
-
Listed below are several terms and phrases associated with basic assumptions, broad accounting principles, and constraints. Pair each item from List A (by letter) with the item from List B that is...
-
In plants, water diffuses out through small openings known as stomatal pores. If D = 2.4 105 m2/s for water vapor in air, and the length of the pores is 2.5 105 m, how long does it take for a water...
-
What is the de Broglie wavelength of an electron with kinetic energy 7.0 TeV?
-
A sheet of paper has length 27.95 cm, width 8.5 in., and thickness 0.10 mm. What is the volume of a sheet of paper in m3? (Volume = length width thickness.)
-
The expected effect on market efficiency of opening a securities market to trading by foreigners would be to: A. Decrease market efficiency. B. Leave market efficiency unchanged. C. Increase market...
-
Suppose that a speculative-grade bond issuer announces, just before bond markets open, that it will default on an upcoming interest payment. In the announcement, the issuer confirms various reports...
-
1. An analyst estimates that a securitys intrinsic value is lower than its market value. The security appears to be: A. Undervalued. B. Fairly valued. C. Overvalued. 2. A market in which assets...
Study smarter with the SolutionInn App