Prims algorithm, Data Structure & Algorithms

Assignment Help:

Prim's algorithm employs the concept of sets. Rather than processing the graph by sorted order of edges, this algorithm processes the edges within the graph randomly by building up disjoint sets.

It employs two disjoint sets A and A. Prim's algorithm works by iterating through the nodes and then determining the shortest edge from the set A to that of set A (that means outside A), followed by the adding up the node to the new graph. While all the nodes are processed, we have a minimum cost spanning tree.

Instead building a sub-graph by inserting one edge at a time, Prim's algorithm builds tree one vertex at a time.

The steps in Prim's algorithm are as:

Consider G be the graph having n vertices for which minimum cost spanning tree is to be made.

Consider T be the minimum spanning tree.

consider T be a single vertex x.

while (T has fewer than n vertices)

{

find the smallest edge connecting T through G-T

add it to T

}

Let the graph of Figure.  And another Figure shows the various steps involved in the construction of Minimum Cost Spanning Tree of graph of this Figure

2433_Prims Algorithm.png

Figure: Construction of Minimum Cost Spanning Tree for the Graph of Figure by application of Prim's algorithm

The following are several steps in the construction of MST for the graph of Figure via Prim's algorithm.

Step 1:  We start along a single vertex (node). Now the set A has this single node and set A has rest of the nodes. Add the edge along the lowest cost from A to A. The edge along cost 4 is added.

Step 2: Lowest cost path through shaded portion of the graph to the rest of the graph (edge along cost 3) is chosen and added to MST.

Step 3: Lowest cost path through shaded portion of the graph to the rest of the graph (edge with cost 6) is chosen and inserted to MST.

Step 4: Lowest cost path from shaded portion of graph to the rest of the graph (edge along cost 73) is chosen and added to MST.

Step 5: The next lowest cost edge to the set not in MST is 8 but makes a cycle. So, it is discarded. The next lowest cost edge 9 is inserted. Now the MST has all the vertices of the graph. This results in the MST of the original graph.

Comparison of Kruskal's algorithm & Prim's algorithm

 

Kruskal's algorithm

Prim's algorithm

Principle

Based on generic minimum cost

spanning tree algorithms

A special case of generic minimum

cost spanning tree algorithm. Operates like Dijkstra's algorithm for finding shortest path in a graph.

Operation

Operates on a single set of

edges in the graph

Operates on two disjoint sets of

edges in the graph

Running time

O(E log E) where E is the

number of edges in the graph

O(E log V), which is

asymptotically same as Kruskal's algorithm

From the above comparison, it might be observed that for dense graphs with more number of edges for a given number of vertices, Prim's algorithm is more efficient.


Related Discussions:- Prims algorithm

Several operations on a aa-tree, The following are several operations on a ...

The following are several operations on a AA-tree: 1. Searching: Searching is done using an algorithm which is similar to the search algorithm of a binary search tree. 2. Ins

Find the adjacency matrix, Consider the digraph G with three vertices P1,P2...

Consider the digraph G with three vertices P1,P2 and P3 and four directed edges, one each from P1 to P2, P1 to P3, P2 to P3 and P3 to P1. a. Sketch the digraph. b. Find the a

Visual Basic Assignment, When writing a code for a program that basically a...

When writing a code for a program that basically answers Relative Velocity questions how do you go at it? How many conditions should you go through?

The two famous methods for traversing, The two famous methods for traversin...

The two famous methods for traversing are:- a) Depth first traversal b) Breadth first

Write a program to create a hashed file, Write a program to create a hashed...

Write a program to create a hashed file that stores the records currently in the file " data_2013 ". Records should use the same fixed-length schema given previously, and should ag

Explain about the preconditions assertion, Preconditions assertion A ...

Preconditions assertion A precondition is an assertion which should be true at the initiation of an operation. For instance, a square root operation can't accept a negative a

Pest control program, PART- Pest Control Program Prepare a Pest Contro...

PART- Pest Control Program Prepare a Pest Control Program for the facility that will address the management of Rodents, Insects and Birds. Your Pest Control Program should

Conversion of forest into tree, Conversion of Forest into Tree A binary...

Conversion of Forest into Tree A binary tree may be used to show an entire forest, since the next pointer in the root of a tree can be used to point to the next tree of the for

Spanning trees, Spanning Trees: A spanning tree of a graph, G, refer to a ...

Spanning Trees: A spanning tree of a graph, G, refer to a set of |V|-1 edges which connect all vertices of the graph. There are different representations of a graph. They are f

Compute the shortest paths to all network nodes, (i)  Consider a system usi...

(i)  Consider a system using flooding with hop counter. Suppose that the hop counter is originally set to the "diameter" (number of hops in the longest path without traversing any

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd