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

Q2.1

The purpose of Dijkstra's is to find the shortest path between nodes in a graph.

Q2.2

BFS iterates in level-order, ordering in-between levels is not important by default. So BFS uses a Queue as it's internal data structure to keep track of the ordering.

Dijkstra's iterates in priority order, prioritizing processing nodes with the next smallest estimated distance (so that we get that guarantee that we're looking at correct information). So Dijkstra's uses a PriorityQueue as it's internal data structure to keep track of the ordering.

Overall they're very similar and Dijkstra's just has a few more steps than BFS.

Question 3

Q3.1-3.6

Here is the final table of Dijkstra's after running it on this graph. This can answer questions 3.1-3.6.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ec88ab96-b047-4e4f-85ea-4aaf580f3f0a/Untitled.png

Below is an explanation of this algorithm being run.

  1. Start by initializing a table where all nodes have distTo=infinity . Set the start vertex (A) to have distTo(A)=0 and edgeTo(A)=/
  2. Dijkstra's Iteration 1: Mark A as known and potentially update all of its neighbors:
  3. Dijkstra's Iteration 2: Mark C as a known vertex, since it is the unknown node with the smallest distTo. Potentially update its neighbors:
  4. Dijkstra's Iteration 3: Mark D as a known vertex, since it is the unknown node with the smallest distTo. Potentially update its neighbors:
  5. Dijkstra's Iteration 4: Mark B as a known vertex, since it is the unknown node with the smallest distTo. Potentially update its neighbors: