Remember, "the answer" is only half of it! Also, make sure everyone in your group can explain why.

We will use this Gradescope Online Assignment as our worksheet for in-class work. These problems are coded as being worth points for our simplicity, but will not impact your grade in the course.

Question 2

Question 2.1

In the shortest path problem we are given a directed graph G and a starting and ending vertex. The goal is to find the shortest path from the start to end vertex. Here, we keep track of the total path length. A different starting vertex will change the whole tree.

In the minimum spanning tree problem we are given an undirected, weighted graph. The goal here is to find the minimum-weight set of edges such that we can get from any vertex in the graph to any other utilizing that set of edges. Here, there is no specific start node because the goal is to minimize the edge weights sum. Most of the time, there is only one possible MST which has the minimum sum. We keep track of the cheapest edges that maintain connectivity.

Question 2.2

Dijkstra's algorithm picks an unknown vertex with smallest cost where cost = distance to the source. On the other hand, Prim's picks an unknown vertex with smallest cost where cost = distance from this vertex to the known set. In other words, the cost of the smallest edge connecting this vertex to the known set. Besides this, the two are practically identical.

Question 3

Question 3.1-3.8

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/f07c9207-1b4d-430a-bd5b-25ef3cb38d7a/CompletePrimAnswer.png

Below is an explanation of this algorithm being run:

  1. Start by initializing a table where all nodes have cost = infinity. Set the start vertex (A) to have cost(A)=0 and prev(A)=/
  2. Prim's Iteration 1: Mark A as known and potentially update all its neighbors
  3. Prim's Iteration 2: Mark D as known and potentially update all its neighbors
  4. Prim's Iteration 3: Mark C as known and potentially update all its neighbors
  5. Prim's Iteration 4: Mark E as known and potentially update all its neighbors
  6. Prim's Iteration 5: Mark B as known and potentially update all its neighbors
  7. Prim's Iteration 6: Mark F as known and potentially update all its neighbors
  8. Prim's Iteration 7: Mark G as known