0% found this document useful (0 votes)
4 views17 pages

MODULE4-Greedy_methods[1]

The document discusses minimum cost spanning trees in undirected connected graphs, defining a spanning tree and introducing Prim's and Kruskal's algorithms for finding minimum spanning trees. Prim's algorithm is a greedy method that builds the tree edge by edge, while Kruskal's algorithm sorts edges by weight and adds them to the subgraph if they do not create a cycle. The time complexity for both algorithms varies based on the data structures used for representation and priority queues.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views17 pages

MODULE4-Greedy_methods[1]

The document discusses minimum cost spanning trees in undirected connected graphs, defining a spanning tree and introducing Prim's and Kruskal's algorithms for finding minimum spanning trees. Prim's algorithm is a greedy method that builds the tree edge by edge, while Kruskal's algorithm sorts edges by weight and adds them to the subgraph if they do not create a cycle. The time complexity for both algorithms varies based on the data structures used for representation and priority queues.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Minimum cost Spanning Tree

Let G= (V, E) be an undirected connected graph. A


subgraph t=(V, E’) of G is a spanning tree of G iff t
is a tree
Spanning tree is a tree in which all nodes are
connected without forming a closed path or
circuit

Fig: A graph and its possible spanning trees


• A spanning tree whose cost is minimum is a minimum cost spanning
tree
Prim’s Algorithm
Greedy method to obtain a minimum –cost spanning
tree.
It builds tree edge by edge
The next edge to include is chosen with a minimum
increase in the sum of the costs of the edges so far
included.
‘A’ is a tree formed by the set of edges selected so far.
The next edge (u,v) to be included in ‘A’ is a
minimum –cost edge not in A with the property that
A U {(u,v)} is also a tree
Prims-Example:
Time complexity for Prim’s algorithm
Depends on the data structures chosen for the graph itself and for the
priority queue
• If a graph is represented by its weight matrix and the priority queue is
implemented as an unordered array, the algorithm’s running time will
be in Θ(|V |2).
• If a graph is represented by its adjacency lists and the priority queue
is implemented as a min-heap, the running time of the algorithm is in
O(|E| log |V |).
Kruskal’s algorithm
• It is named Kruskal’s algorithm after Joseph Kruskal, who discovered
this algorithm when he was a second-year graduate student
• Kruskal’s algorithm looks at a minimum spanning tree of a weighted
connected graph G = V, E as an acyclic subgraph with |V| − 1 edges
for which the sum of the edge weights is the smallest.
• The algorithm begins by sorting the graph’s edges in non decreasing
order of their weights.

• Then, starting with the empty subgraph, it scans this sorted list,
adding the next edge on the list to the current subgraph if such an
inclusion does not create a cycle and simply skipping the edge
otherwise.
1 Find MST using Kruskal’s Algorithm
Kruskal’s algorithm
Example:

You might also like