CHAPTER 25 Weighted Graphs and Applications Objectives ⢠To ...
CHAPTER 25 Weighted Graphs and Applications Objectives ⢠To ...
CHAPTER 25 Weighted Graphs and Applications Objectives ⢠To ...
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
TTT<br />
TTT<br />
TTT<br />
The number of flips is 8<br />
The program prompts the user to enter an initial node with nine letters H’s <strong>and</strong> T’s in lines 9–13, creates a<br />
model (line 16), obtains a shortest path from the initial node to the target node (lines 17–18), displays the<br />
nodes in the path (lines 20–21), <strong>and</strong> invokes getNumberOfFlips to get the number of flips needed to<br />
reach to the target node (lines 23–24).<br />
Check point<br />
<strong>25</strong>.15 Why is the tree data field in NineTailModel in Listing 24.9 defined protected?<br />
<strong>25</strong>.16 How are the nodes created for the graph in <strong>Weighted</strong>NineTailModel?<br />
<strong>25</strong>.17 How are the edges created for the graph in <strong>Weighted</strong>NineTailModel?<br />
Key Terms<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Dijkstra’s algorithm<br />
edge-weighted graph<br />
minimum spanning tree<br />
Prim’s algorithm<br />
shortest path<br />
single-source shortest path<br />
vertex-weighted graph<br />
Chapter Summary<br />
1. Often a priority queue is used to represent weighted edges, so that the minimum-weight edge can<br />
be retrieved first.<br />
2. A spanning tree of a graph is a subgraph that is a tree <strong>and</strong> connects all vertices in the graph.<br />
3. Prim’s algorithm for finding a minimum spanning tree works as follows: the algorithm starts with<br />
a spanning tree T that contains an arbitrary vertex. The algorithm exp<strong>and</strong>s the tree by adding a<br />
vertex with the minimum-weight edge incident to a vertex already in the tree.<br />
44