Question: Since T is implemented using a list in the getMinimumSpanningTree and getShortestPath methods in Listing 29.2, WeightedGraph.java, testing whether a vertex u is in T

Since T is implemented using a list in the getMinimumSpanningTree and getShortestPath methods in Listing 29.2, WeightedGraph.java, testing whether a vertex u is in T by invoking T.contains(u) takes O(n) time. Modify these two methods by introducing an array named isInT. Set isInT[u] to true when a vertex u is added to T. Testing whether a vertex u is in T can now be done in O(1) time. Write a test program using the following code, where graph1 is created from Figure 29.1:

WeightedGraph

Data from Listing 29.2,

WeightedGraph

Step by Step Solution

3.37 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import javautil public class Exercise2920 public static void mainString args String vertices Seattle San Francisco Los Angeles Denver Kansas City Chicago Boston New York Atlanta Miami Dallas Houston i... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction to Java Programming and Data Structure Questions!