Skip to main content
\(\newcommand{\set}[1]{\{1,2,\dotsc,#1\,\}} \newcommand{\ints}{\mathbb{Z}} \newcommand{\posints}{\mathbb{N}} \newcommand{\rats}{\mathbb{Q}} \newcommand{\reals}{\mathbb{R}} \newcommand{\complexes}{\mathbb{C}} \newcommand{\twospace}{\mathbb{R}^2} \newcommand{\threepace}{\mathbb{R}^3} \newcommand{\dspace}{\mathbb{R}^d} \newcommand{\nni}{\mathbb{N}_0} \newcommand{\nonnegints}{\mathbb{N}_0} \newcommand{\dom}{\operatorname{dom}} \newcommand{\ran}{\operatorname{ran}} \newcommand{\prob}{\operatorname{prob}} \newcommand{\Prob}{\operatorname{Prob}} \newcommand{\height}{\operatorname{height}} \newcommand{\width}{\operatorname{width}} \newcommand{\length}{\operatorname{length}} \newcommand{\crit}{\operatorname{crit}} \newcommand{\inc}{\operatorname{inc}} \newcommand{\HP}{\mathbf{H_P}} \newcommand{\HCP}{\mathbf{H^c_P}} \newcommand{\GP}{\mathbf{G_P}} \newcommand{\GQ}{\mathbf{G_Q}} \newcommand{\AG}{\mathbf{A_G}} \newcommand{\GCP}{\mathbf{G^c_P}} \newcommand{\PXP}{\mathbf{P}=(X,P)} \newcommand{\QYQ}{\mathbf{Q}=(Y,Q)} \newcommand{\GVE}{\mathbf{G}=(V,E)} \newcommand{\HWF}{\mathbf{H}=(W,F)} \newcommand{\bfC}{\mathbf{C}} \newcommand{\bfG}{\mathbf{G}} \newcommand{\bfH}{\mathbf{H}} \newcommand{\bfF}{\mathbf{F}} \newcommand{\bfI}{\mathbf{I}} \newcommand{\bfK}{\mathbf{K}} \newcommand{\bfP}{\mathbf{P}} \newcommand{\bfQ}{\mathbf{Q}} \newcommand{\bfR}{\mathbf{R}} \newcommand{\bfS}{\mathbf{S}} \newcommand{\bfT}{\mathbf{T}} \newcommand{\bfNP}{\mathbf{NP}} \newcommand{\bftwo}{\mathbf{2}} \newcommand{\cgA}{\mathcal{A}} \newcommand{\cgB}{\mathcal{B}} \newcommand{\cgC}{\mathcal{C}} \newcommand{\cgD}{\mathcal{D}} \newcommand{\cgE}{\mathcal{E}} \newcommand{\cgF}{\mathcal{F}} \newcommand{\cgG}{\mathcal{G}} \newcommand{\cgM}{\mathcal{M}} \newcommand{\cgN}{\mathcal{N}} \newcommand{\cgP}{\mathcal{P}} \newcommand{\cgR}{\mathcal{R}} \newcommand{\cgS}{\mathcal{S}} \newcommand{\bfn}{\mathbf{n}} \newcommand{\bfm}{\mathbf{m}} \newcommand{\bfk}{\mathbf{k}} \newcommand{\bfs}{\mathbf{s}} \newcommand{\bijection}{\xrightarrow[\text{onto}]{\text{$1$--$1$}}} \newcommand{\injection}{\xrightarrow[]{\text{$1$--$1$}}} \newcommand{\surjection}{\xrightarrow[\text{onto}]{}} \newcommand{\nin}{\not\in} \newcommand{\prufer}{\mbox{prüfer}} \DeclareMathOperator{\fix}{fix} \DeclareMathOperator{\stab}{stab} \DeclareMathOperator{\var}{var} \newcommand{\inv}{^{-1}} \newcommand{\lt}{<} \newcommand{\gt}{>} \newcommand{\amp}{&} \)

Section12.5Exercises

1

For the graph in Figure 12.20, use Kruskal's algorithm (“avoid cycles”) to find a minimum weight spanning tree. Your answer should include a complete list of the edges, indicating which edges you take for your tree and which (if any) you reject in the course of running the algorithm.

<<SVG image is unavailable, or your browser cannot render it>>

Figure12.20Find a minimum weight spanning tree
2

For the graph in Figure 12.20, use Prim's algorithm (“build tree”) to find a minimum weight spanning tree. Your answer should list the edges selected by the algorithm in the order they were selected.

3

For the graph in Figure 12.21, use Kruskal's algorithm (“avoid cycles”) to find a minimum weight spanning tree. Your answer should include a complete list of the edges, indicating which edges you take for your tree and which (if any) you reject in the course of running the algorithm.

<<SVG image is unavailable, or your browser cannot render it>>

Figure12.21Find a minimum weight spanning tree
4

For the graph in Figure 12.21, use Prim's algorithm (“build tree”) to find a minimum weight spanning tree. Your answer should list the edges selected by the algorithm in the order they were selected.

5

For the graph in Figure 12.22, use Kruskal's algorithm (“avoid cycles”) to find a minimum weight spanning tree. Your answer should include a complete list of the edges, indicating which edges you take for your tree and which (if any) you reject in the course of running the algorithm.

<<SVG image is unavailable, or your browser cannot render it>>

Figure12.22Find a minimum weight spanning tree
6

For the graph in Figure 12.22, use Prim's algorithm (“build tree”) to find a minimum weight spanning tree. Your answer should list the edges selected by the algorithm in the order they were selected.

7

A new local bank is being created and will establish a headquarters \(h\text{,}\) two branches \(b_1\) and \(b_2\text{,}\) and four ATMs \(a_1\text{,}\) \(a_2\text{,}\) \(a_3\text{,}\) and \(a_4\text{.}\) They need to build a computer network such that the headquarters, branches, and ATMs can all intercommunicate. Furthermore, they will need to be networked with the Federal Reserve Bank of Atlanta, \(f\text{.}\) The costs of the feasible network connections (in units of $10,000) are listed below:

\begin{align*} h f \amp \quad 80 \amp h b_1 \amp \quad 10\amp h b_2 \amp \quad 20\amp b_1 b_2 \amp \quad 8\\ f b_1 \amp \quad 12\amp f a_1 \amp \quad 20\amp b_1 a_1 \amp \quad 3\amp a_1 a_2 \amp \quad 13\\ h a_2 \amp \quad 6\amp b_2 a_2 \amp \quad 9\amp b_2 a_3 \amp \quad 40\amp a_1 a_4 \amp \quad 3\\ a_3 a_4 \amp \quad 6 \end{align*}

The bank wishes to minimize the cost of building its network (which must allow for connection, possibly routed through other nodes, from each node to each other node), however due to the need for high-speed communication, they must pay to build the connection from \(h\) to \(f\) as well as the connection from \(b_2\) to \(a_3\text{.}\) Give a list of the connections the bank should establish in order to minimize their total cost, subject to this constraint. Be sure to explain how you selected the connections and how you know the total cost is minimized.

8

A disconnected weighted graph obviously has no spanning trees. However, it is possible to find a spanning forest of minimum weight in such a graph. Explain how to modify both Kruskal's algorithm and Prim's algorithm to do this.

10

In the paper where Kruskal's algorithm first appeared, he considered the algorithm a route to a nicer proof that in a connected weighted graph with no two edges having the same weight, there is a unique minimum weight spanning tree. Prove this fact using Kruskal's algorithm.

11

Use Dijkstra's algorithm to find the distance from \(a\) to each other vertex in the digraph shown in Figure 12.23 and a directed path of that length.

<<SVG image is unavailable, or your browser cannot render it>>

Figure12.23A directed graph
12

Table 12.24 contains the length of the directed edge \((x,y)\) in the intersection of row \(x\) and column \(y\) in a digraph with vertex set \(\{a,b,c,d,e,f\}\text{.}\) For example, \(w(b,d)=21\text{.}\) (On the other hand, \(w(d,b)=10\text{.}\)) Use this data and Dijkstra's algorithm to find the distance from \(a\) to each of the other vertices and a directed path of that length from \(a\text{.}\)

\(w\) \(a\) \(b\) \(c\) \(d\) \(e\) \(f\)
\(a\) 0 12 8 43 79 35
\(b\) 93 0 18 21 60 33
\(c\) 17 3 0 37 50 30
\(d\) 85 10 91 0 17 7
\(e\) 28 47 39 14 0 108
\(f\) 31 7 29 73 20 0
Table12.24A digraph represented as a table of data
13

Use Dijkstra's algorithm to find the distance from \(a\) to each other vertex in the digraph shown in Figure 12.25 and a directed path of that length.

<<SVG image is unavailable, or your browser cannot render it>>

Figure12.25A directed graph
14

Table 12.26 contains the length of the directed edge \((x,y)\) in the intersection of row \(x\) and column \(y\) in a digraph with vertex set \(\{a,b,c,d,e,f\}\text{.}\) For example, \(w(b,d)=47\text{.}\) (On the other hand, \(w(d,b)=6\text{.}\)) Use this data and Dijkstra's algorithm to find the distance from \(a\) to each of the other vertices and a directed path of that length from \(a\text{.}\)

\(w\) \(a\) \(b\) \(c\) \(d\) \(e\) \(f\)
\(a\) 0 7 17 55 83 42
\(b\) 14 0 13 47 27 17
\(c\) 37 42 0 16 93 28
\(d\) 10 6 8 0 4 32
\(e\) 84 19 42 8 0 45
\(f\) 36 3 76 5 17 0
Table12.26A digraph represented as a table of data
15

Give an example of a digraph having an undirected path between each pair of vertices, but having a root vertex \(r\) so that Dijkstra's algorithm cannot find a path of finite length from \(r\) to some vertex \(x\text{.}\)

16

Notice that in our discussion of Dijkstra's algorithm, we required that the edge weights be nonnegative. If the edge weights are lengths and meant to model distance, this makes perfect sense. However, in some cases, it might be reasonable to allow negative edge weights. For example, suppose that a positive weight means there is a cost to travel along the directed edge while a negative edge weight means that you make money for traveling along the directed edge. In this case, a directed path with positive total weight results in paying out to travel it, while one with negative total weight results in a profit.

  1. Give an example to show that Dijkstra's algorithm does not always find the path of minimum total weight when negative edge weights are allowed.

  2. Bob and Xing are considering this situation, and Bob suggests that a little modification to the algorithm should solve the problem. He says that if there are negative weights, they just have to find the smallest (i.e., most negative weight) and add the absolute value of that weight to every directed edge. For example, if \(w(x,y)\geq -10\) for every directed edge \((x,y)\text{,}\) Bob is suggesting that they add \(10\) to every edge weight. Xing is skeptical, and for good reason. Give an example to show why Bob's modification won't work.