Problem 1

a)

Transclude of ECS122A-HW5-2024-12-05-21.51.39.excalidraw

b)

Run BFS from A and fill out the distance array d:


Problem 2

1)
00
720
537
245
450
164
867
362
965
679
10106
2)

Transclude of ECS122A-HW5-2024-12-05-22.39.58.excalidraw

Topological Sort:


Problem 3

Find the shortest path tree from every node to node 1 for the graph of Fig.1 using the Bellman-Ford and Dijkstra algorithms. Describe the algorithmic change necessary to answer this question.

  • The first step to run this algorithm is to reverse all of the edges, and find the shortest path from 1 to every other node
  • Since the graph has purely positive weights, the resulting shortest path tree will be identical for both Bellman-Ford and Djisktra
DistancePath
101
242->1
353->1
474->2->1
5125->6->4->2->1
6106->4->2->1
7127->6->4->2->1

Transclude of ECS122A-HW5-2024-12-05-23.36.32.excalidraw

  • Resulting tree visualized