CHAPTER 25 Weighted Graphs and Applications Objectives ⢠To ...
CHAPTER 25 Weighted Graphs and Applications Objectives ⢠To ...
CHAPTER 25 Weighted Graphs and Applications Objectives ⢠To ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
***<strong>25</strong>.11 (Test if a vertex in T effeciently) Since T is implemented using a list in the<br />
getMinimumSpanningTree <strong>and</strong> getShortestPath functions in Listing <strong>25</strong>.2<br />
<strong>Weighted</strong>Graph.cpp, testing whethere a vertex u is in T by invoking the STL find<br />
algorithm takes O(n) time. Modify these two functions by introducing an array named<br />
isInT. Set isInT[u] to true when a vertex u is added to T. Testing whethere a vertex<br />
u is in T can now be done in O(1) time. Write a test program using following code, where<br />
graph1, printTree, <strong>and</strong> printAllPath are the same as in Listings <strong>25</strong>.6 <strong>and</strong> <strong>25</strong>.9:<br />
<strong>Weighted</strong>Graph graph1(vectorOfVertices, edgeVector);<br />
MST tree1 = graph1.getMinimumSpanningTree();<br />
cout