Question: You are to write a function min _ dist _ tree ( graph , source ) that takes in a connected, weighted graph and a

You are to write a function min_dist_tree(graph, source) that takes in a connected, weighted graph and a vertex as its input, and then returns the minimum distance tree produced by Dijkstra's Algorithm with 'source' as its root. Note that since the input graph will be connected, the resulting tree will be spanning.
print(min_dist_tree({"A" : [["B",10],["D",5]],"B" : [["A",10],["C",5]],"C" : [["B",5],["D",15]],"D" : [["C",15],["A",5]]},"A"))
This should return
{"A":["B","D"],"B":["C"],"C":[],"D":[]}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!