Skip to main content
Mathematics LibreTexts

12.5: Exercises

  • Page ID
    97948
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    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.

    Screen Shot 2022-03-12 at 1.14.36 AM.png
    Figure 12.20. Find 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.

    Screen Shot 2022-03-12 at 1.15.42 AM.png
    Figure 12.21. Find 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.

    Screen Shot 2022-03-12 at 1.16.48 AM.png
    Figure 12.22. Find 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\), two branches \(b_1\) and \(b_2\), and four ATMs \(a_1\), \(a_2\), \(a_3\), and \(a_4\). 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\). The costs of the feasible network connections (in units of $10,000) are listed below:

    Screen Shot 2022-03-12 at 1.18.08 AM.png

    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\). 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.

    9. Prove Proposition 12.3.

    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.

    Screen Shot 2022-03-12 at 1.20.49 AM.png
    Figure 12.23. A directed graph

    12. Figure 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\}\). For example, \(w(b,d)=21\). (On the other hand, \(w(d,b)=10\).) 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\).

    Screen Shot 2022-03-12 at 1.22.59 AM.png
    Figure 12.24. A 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.

    Screen Shot 2022-03-12 at 1.23.33 AM.png
    Figure 12.25. A directed graph

    14. Figure 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\}\). For example, \(w(b,d)=47\). (On the other hand, \(w(d,b)=6\).) 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\).

    Screen Shot 2022-03-12 at 1.25.51 AM.png
    Figure 12.26. A 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\).

    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.

    a. 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.

    b. 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)≥−10\) for every directed edge \((x,y)\), 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.


    This page titled 12.5: Exercises is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by Mitchel T. Keller & William T. Trotter via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?