Minimum Spanning Tree
Minimum Spanning Tree
Minimum Spanning Tree
Prims Algorithm
What is Tree?
In tree there is exactly one root node and every child have only one
parent.
Different types of trees are : Binary Tree , Binary Search Tree, AVL
tree, Heaps.
Example of a Tree:
A complete undirected
graph can have maximum
nn-2 number of spanning
trees, where n is the
number of nodes.
All possible spanning trees of graph G, have the same number of edges
and vertices.
Network design
Indirect Applications
Minimum Spanning-Tree
1.
Kruskals Algorithm
2.
Prims Algorithm
Prim's algorithm to find minimum cost spanning tree (as
Kruskal's algorithm) uses the greedy approach. Prim's
algorithm shares a similarity with theshortest path
firstalgorithms.
Prim's algorithm, in contrast with Kruskal's algorithm, treats
the nodes as a single tree and keeps on adding new nodes to
the spanning tree from the given graph.
Prims Algorithm
Lets take a example:
Prims Algorithm
Step 1 - Remove all loops and parallel edges
Prims Algorithm
Step 1 - Remove all loops and parallel edges
Prims Algorithm
Step 2 - Choose any arbitrary node as root node
In this case, we will use S as our arbitrary node for the
spanning tree.
Prims Algorithm
Step 3 - Check outgoing edges and select the one with less
cost
Prims Algorithm
Step 3 - Check outgoing edges and select the one with less
cost
Prims Algorithm
Step 3 - Check outgoing edges and select the one with less
cost
Prims Algorithm
We may find that the output spanning tree of the same graph
using two different algorithms is same.
Prims Algorithm
Lets have a question: