Prim’s MST Algorithm: Tracing

Run the Prim’s algorithm implemented using a priority queue (see below) against the graph shown below. Give your answers as follows.

  1. Run the algorithm assuming the node a is picked as the start node s, and show the algorithm run trace (see the specification below).
  2. Run the algorithm assuming the node g is picked as the start node s, and show the algorithm run trace (see the specification below).
  3. Draw the resulting minimum spanning tree on the graph. Show the included edges in colored or thick lines.

Specification of the algorithm run tracing: For each algorithm run tracing, show the content of the cut , the content of the , and the content of the priority queue at the end of the While loop in each iteration. Specifically, show the content of as a set of nodes, the content of as a set of edges, and the content of as a set of ordered pairs of a node number and a priority key. (For ease of grading, please show the end nodes of an edge in the alphabetical order (e.g., (a, d)), and list the priority queue elements in the alphabetic order of node number.) For example, when the start node is , their contents before the 1st iteration is , , and .

Given Prim Pseudocode

Given Undirected Graph

1. Starting at Node

Let indicate iteration number.

2. Starting at Node

Let indicate iteration number.

3. MST Drawing

MST of provided undirected graph


Kruskal’s MST Algorithm Tracing

Run the Kruskal’s MST algorithm shown below (left) on the graph shown below (right), using disjoint sets data structure represented as a forest. Provide your answer as instructed below.

  1. List the edges after the sorting (format: “(v1, v2), (v3, v4),…”).
  2. Draw the forest structure after MakeUnionFind.
  3. In each iteration of the ‘for’ loop, write the trace of Find and Union operations (e.g., “Find(v) returns u.”, “Do Union(v1, v2).”, “Discard (v1, v2).”), and draw the resulting forest structure. Use the union-by-size heuristic for Union.
  4. After the algorithm terminates, draw the final MST of the graph (by making the included edges thicker or red). (There is no need to show the MST in every iteration.)

Please follow this specification for the consistency and convenience of grading:

  • Iterate the ‘for’ loop over all edges (without an early termination), as written in the algorithm.
  • When drawing a forest, show the trees in an increasing order of the root node number.
  • If the disjoint sets do not change in an iteration, you do not need to show the forest structure.
  • If two trees that are merged have the same size, make the second tree (on the right) a subtree of the first tree (on the left).

Kruskal Pseudocode Algorithm

Sample Undirected Graph

1. Sorting the Edgeso

Sorting the edges yields:

2. Resulting Forest Structure from

This just yields each node having its own tree with a size of :

3. Iterating over Traces

Once again letting indicate iteration.

4. Final MST

Resulting MST for Second Undirected Graph Sample