[Solved] A Prims algorithm to find the minimum spanning tree

$25

File Name: A_Prims_algorithm_to_find_the_minimum_spanning_tree.zip
File Size: 480.42 KB

SKU: [Solved] A Prim’s algorithm to find the minimum spanning tree Category: Tag:
5/5 - (1 vote)

In Prims algorithm, two sets are maintained, one set contains list of vertices already included in MST, other set contains vertices not yet included. With adjacency list representation, all vertices of a graph can be traversed in O(V+E) time using BFS. The idea is to traverse all vertices of graph using BFS and use a Min Heap to store the vertices not yet included in MST. Min Heap is used as a priority queue to get the minimum weight edge from the cut. Min Heap is used as time complexity of operations like extracting minimum element and decreasing key value is O(LogV) in Min Heap.

Following are the detailed steps.1) Create a Min Heap of size V where V is the number of vertices in the given graph. Every node of min heap contains vertex number and key value of the vertex.2) Initialize Min Heap with first vertex as root (the key value assigned to first vertex is 0). The key value assigned to all other vertices is INF (infinite).3) While Min Heap is not empty, do following..a) Extract the min value node from Min Heap. Let the extracted vertex be u…b) For every adjacent vertex v of u, check if v is in Min Heap (not yet included in MST). If v is in Min Heap and its key value is more than weight of u-v, then update the key value of v as weight of u-v.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] A Prims algorithm to find the minimum spanning tree
$25