Complete the code to initialize the starting vertex in Prim's algorithm.
visited = set()
start_vertex = [1]
visited.add(start_vertex)Prim's algorithm starts from a vertex, often vertex 0 in zero-indexed graphs.
Complete the code to select the edge with the minimum weight from the priority queue.
while edges: weight, vertex = heapq.heappop([1]) if vertex not in visited: break
Prim's algorithm uses a priority queue (often a heap) named 'edges' to pick the smallest edge.
Fix the error in the code that adds new edges to the priority queue.
for neighbor, weight in graph[vertex]: if neighbor not in visited: heapq.heappush(edges, ([1], neighbor))
Edges are pushed with their weight first to maintain the priority queue order by weight.
Fill both blanks to correctly update the total cost and add the new vertex to visited.
total_cost [1]= weight visited.[2](vertex)
We add the edge weight to total_cost and add the vertex to the visited set.
Fill all three blanks to complete the dictionary comprehension that maps vertices to their minimum edge weights.
min_edges = {vertex: [1] for vertex, [2] in graph.items() if [3]This comprehension finds the minimum edge weight for each vertex not yet visited.