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:

Data from Listing 29.2,





WeightedGraph
Step by Step Solution
3.37 Rating (156 Votes )
There are 3 Steps involved in it
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
Get step-by-step solutions from verified subject matter experts
