Week 08 Tutorial Notes

Graphs (ii)

Group Question

  1. Run Dijkstra's algorithm on the following weighted graph starting from vertex \(A\), and answer the following questions.



    1. Fill in both the distance and predecessor arrays.
    2. Highlight the shortest path from A to each vertex.
    3. What is the shortest path to Vertex \(D\)? List out the nodes along the path.

  2. Consider the following weighted graph. We have partially executed an algorithm to find the MST. The edges that have been selected so far have been highlighted in blue.

  3. Continue finding the MST from the above graph using:
    1. Prim's algorithm. Give the order the edges are added (Example [\(A\)-\(E\)], [\(E\)-\(B\)], etc).
    2. Kruskal's algorithm. Give the order the edges are added.
    3. What is the cost of the resulting MST?

  4. Suppose Dijkstra's algorithm was executed on an undirected graph starting from vertex \(C\), the following distance and predecessor arrays are obtained.

  5. Vertex A B C D E F
    Distance 5 4 0 3 9 8
    Predecessor D C - C B A

    1. From the resulting Dijkstra's traversal draw in the edges on the graph on the left.
    2. Is it possible to calculate the shortest distance between the following vertices? And if so what is the distance?
      • \(C\) to \(A\).
      • \(B\) to \(C\).
      • \(E\) to \(F\).
      • \(D\) to \(F\).
    3. Is it possible for the following edges to exist in the full graph?
      • \(E\) to \(D\) with edge weight 7.
      • \(A\) to \(E\) with edge weight 3.
      • \(B\) to \(D\) with edge weight 1.




Group Work Answers:

Click each section to reveal.


    Vertex A B C D E F
    Distance 0 1 5 6 2 4
    Predecessor - A B F A B

  • The shortest path is \(A\) - \(B\) - \(F\) - \(D\).

    The final MST is the same for both Prim's and Kruskal's Algorithm, with a cost of 26.

    However the edges are selected in different orders.
  • Prim's: [\(C\)-\(G\)], [\(G\)-\(J\)], [\(H\)-\(I\)], [\(B\)-\(F\)], [\(A\)-\(B\)].
  • Kruskal's: [\(A\)-\(B\)], [\(G\)-\(J\)], [\(C\)-\(G\)], [\(H\)-\(I\)], [\(B\)-\(F\)].


  1. Is it possible to calculate the shortest distances?
    • Yes. The distance from \(C\) to \(A\) is 5.
    • Yes. The distance from \(B\) to \(C\) is 4.
    • No.
    • Yes. The distance from \(D\) to \(F\) is 5.
  2. Do the following edges exist?
    • Yes
    • No. Because the shortest path to \(E\) would then become: \(C\) - \(D\) - \(A\) - \(E\) with a distance of 8.
    • Yes. There would be a tie in the shortest path to node \(B\) with a distance of 4: \(C\) - \(D\) - \(B\)