e. (6 marks) Hence write the following Java method in class GraphApplic as a modification of...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
e. (6 marks) Hence write the following Java method in class GraphApplic as a modification of a breadth- first traversal, to add up all the distances from source vertex v to every other vertex within a single connected component. public Integer sumDistances (Integer v) { // PRE: v is the id of a vertex in the graph; distances have been calculated from v using calcDistances () // POST: Sums all distances from v to every other vertex in a connected component } In the graph above, sumDistances (100) would return 9; the table below shows the indi- vidual distances. vertex u vertex v distance d(u, v) 100 100 100 100 100 (total) 60 A As A; Page 11 2 public Boolean moreCentral (Integer v, Integer u) { // PRE: v, u are the ids of vertices in the graph 2 3 9 Include the code for the whole function in your submission. f. (4 marks) A vertex v is considered MORE CENTRAL to a graph than a vertex u if the sum of all distances from v to every other vertex is smaller than the sum of all distances from u to every other vertex. Using any functions defined above, write the following Java method in class GraphApplic. // POST: Returns True if v is more central than u, False otherwise } Note that the method will return false if u and have the same sums of distances. In the graph above, vertex 100 is more central than vertex A, as the sum of all distances for the former is 9, and for the latter is 13. SECTION B (3 QUESTIONS, 86 MARKS) Question 6. [32 marks in total] For this question, assume the definition of Java graph classes used in lectures and given in the Appendix. You may make use of any functions given in these classes. 100 60 A A As } 40 A A A3 A a. (4 marks) Consider the undirected graph above. Replace the vertices labelled A. Ag according to the UNIQUESINGLEDIGIT representation of your own student number, as described above in Question 1. Then give the adjacency list representation for the graph. Page 10 vertex u vertex v 40 40 As b. (8 marks) Consider the undirected graph you obtained from replacing A... As with numbers in a. above. Give the breadth-first traversal of the connected component containing vertex 40, starting from vertex 40. At any vertex where there is a choice of edge you should choose the next vertex to be visited based on ascending order. 50 c. (3 marks) Define the DISTANCE d(u, v) between two vertices u and in a graph as being the minimal number of edges between them. The distance from a vertex to itself is 0; if the graph is not connected, and there is no path between the vertices u and v, the distance is 0. In the example graph above, the following are some example distances. 40 50 70 70 A A7 70 distance d(u, v) 0 1 3 A7 2 What is the distance from vertex 40 to vertex 70? d. (7 marks) Write the following Java method in class GraphApplic as a modification of a breadth- first traversal, to label each vertex with its distance from source vertex v within a single connected component. You can assume that the Vertex class contains an attribute dist for storing this value, and methods set Dist() and getDist() for accessing it. Include the code for the whole function in your submission. public void calcDistances (Integer v) { // PRE: v is the id of a vertex in the graph // POST: Calculates and stores distance between v, all other vertices // in a connected component; distances are stored in each vertex e. (6 marks) Hence write the following Java method in class GraphApplic as a modification of a breadth- first traversal, to add up all the distances from source vertex v to every other vertex within a single connected component. public Integer sumDistances (Integer v) { // PRE: v is the id of a vertex in the graph; distances have been calculated from v using calcDistances () // POST: Sums all distances from v to every other vertex in a connected component } In the graph above, sumDistances (100) would return 9; the table below shows the indi- vidual distances. vertex u vertex v distance d(u, v) 100 100 100 100 100 (total) 60 A As A; Page 11 2 public Boolean moreCentral (Integer v, Integer u) { // PRE: v, u are the ids of vertices in the graph 2 3 9 Include the code for the whole function in your submission. f. (4 marks) A vertex v is considered MORE CENTRAL to a graph than a vertex u if the sum of all distances from v to every other vertex is smaller than the sum of all distances from u to every other vertex. Using any functions defined above, write the following Java method in class GraphApplic. // POST: Returns True if v is more central than u, False otherwise } Note that the method will return false if u and have the same sums of distances. In the graph above, vertex 100 is more central than vertex A, as the sum of all distances for the former is 9, and for the latter is 13. SECTION B (3 QUESTIONS, 86 MARKS) Question 6. [32 marks in total] For this question, assume the definition of Java graph classes used in lectures and given in the Appendix. You may make use of any functions given in these classes. 100 60 A A As } 40 A A A3 A a. (4 marks) Consider the undirected graph above. Replace the vertices labelled A. Ag according to the UNIQUESINGLEDIGIT representation of your own student number, as described above in Question 1. Then give the adjacency list representation for the graph. Page 10 vertex u vertex v 40 40 As b. (8 marks) Consider the undirected graph you obtained from replacing A... As with numbers in a. above. Give the breadth-first traversal of the connected component containing vertex 40, starting from vertex 40. At any vertex where there is a choice of edge you should choose the next vertex to be visited based on ascending order. 50 c. (3 marks) Define the DISTANCE d(u, v) between two vertices u and in a graph as being the minimal number of edges between them. The distance from a vertex to itself is 0; if the graph is not connected, and there is no path between the vertices u and v, the distance is 0. In the example graph above, the following are some example distances. 40 50 70 70 A A7 70 distance d(u, v) 0 1 3 A7 2 What is the distance from vertex 40 to vertex 70? d. (7 marks) Write the following Java method in class GraphApplic as a modification of a breadth- first traversal, to label each vertex with its distance from source vertex v within a single connected component. You can assume that the Vertex class contains an attribute dist for storing this value, and methods set Dist() and getDist() for accessing it. Include the code for the whole function in your submission. public void calcDistances (Integer v) { // PRE: v is the id of a vertex in the graph // POST: Calculates and stores distance between v, all other vertices // in a connected component; distances are stored in each vertex
Expert Answer:
Answer rating: 100% (QA)
Heres the modified code for the sumDistances method and the moreCentral method in the GraphApplic cl... View the full answer
Related Book For
Smith and Roberson Business Law
ISBN: 978-0538473637
15th Edition
Authors: Richard A. Mann, Barry S. Roberts
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
In each case, verily that the points P and Q lie on the line. x = 4 - t P(2, 3, -3), Q(-1, 3, -9) y = 3 z = 1 - 2t
-
Where in the atom is most of its mass concentrated?
-
Explain three consequences of inflation.
-
What are the elements and principles of the COSO framework?
-
General Hospitals patient account division has compiled data on the age of accounts receivable. The data collected indicate that the age of the accounts follows a normal distribution with = 28 days...
-
When the discontinued component is sold before the end of the reporting period, they must report Multiple choice question. operating income or loss, and gain or loss on disposal, both after related...
-
K Ltd. paid an employee a tax-free travel allowance of $5,200 based on 9,000 kilometres of out-of-town driving. What amount can K deduct for tax purposes?
-
Two classes took the same test. One class of 25 students made an average grade of 82%, the other class of 32 students made an average grade of 75%. The average grade for all students in both classes...
-
The catalytic cracking of a gas oil charge. A, to form C,+ (B) and to form coke and dry gas (C) is to be carried out in a screw-type conveyor moving-bed reactor at 900F: kB Cs Gas oil kc Dry gas,...
-
Can you elaborate on the intricate mechanisms underlying preemptive multitasking, particularly in the context of real-time operating systems, and the challenges encountered in guaranteeing...
-
WRITE IN THREE (3) FULL AND COMPLETE PARAGRAPHS, WITH EACH PARAGRAPH CONTAINING AT LEAST THREE (3) FULL AND COMPLETE SENTENCES, YOUR ORIGINAL RESPONSES TO THE FOLLOWING QUESTIONS: 1. Do you think the...
-
10 points English Petroleum (EP) has to decide whether or not to drill for oil in a particular place. After its recent disaster in gulf, it has decided to conduct a thorough analysis before venturing...
-
In its previous annual report, Diamond Company had net income of $1,400 million, and non-cash charges of $300 million. There were 110 million shares outstanding. Diamond's share price was $40 per...
-
A firm's production function is given by Q = 8L K + 7L Unit capital and labour costs are $1 and $7 respectively and total input costs are $500. (a) Find the values of L and K which maximise output....
-
Test your confidence in the following Project Decisions: SI. # Question 01 02 03 04 05 06 07 08 09 10 How many years did it take to construct the largest Egyptian Pyramid- Pyramid of Cheops? When was...
-
Sims contracted in writing to sell Blake one hundred electric motors at a price of $100 each, freight prepaid to Blakes warehouse. By the contract of sale, Sims expressly warranted that each motor...
-
Jacobs, owner of a farm, entered into a contract with Earl Walker in which Walker agreed to paint the buildings on the farm. As authorized by Jacobs, Walker acquired the paint from Jones with the...
-
Lile, an insurance broker who handled all insurance for Tempo Co., purchased a fire policy from Insurance Company insuring Tempo Co.s factory against fire in the amount of $1.5 million. Before the...
-
Figure P4.2 shows the velocity of a block of wood as a function of time. The block is sliding over a horizontal surface. Describe the physical processes that led to this graph. Data from Figure P4.2...
-
Consider the two velocity-versus-time graphs shown in Figure P4.4. Are the motions represented by these curves best described as similar or as different? Is the effect of friction on the motion...
-
The velocity-versus-time graph in Figure P4.3 shows the motion of two different objects sliding across a horizontal surface. Could the change in the \(x\) component of velocity with time be...
Study smarter with the SolutionInn App