0% found this document useful (0 votes)
33 views

Min Span Tree

The document discusses algorithms for finding minimum weight spanning trees in graphs, including Kruskal's algorithm, Prim's algorithm, and Dijkstra's algorithm. Kruskal's algorithm finds a minimum spanning tree by greedily adding edges in order of increasing weight without introducing cycles. Prim's algorithm finds the minimum spanning tree by growing a tree one vertex at a time, each time adding the edge with smallest weight that connects the growing tree to a new vertex. The document provides an example applying these algorithms.

Uploaded by

Sumit Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
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)
33 views

Min Span Tree

The document discusses algorithms for finding minimum weight spanning trees in graphs, including Kruskal's algorithm, Prim's algorithm, and Dijkstra's algorithm. Kruskal's algorithm finds a minimum spanning tree by greedily adding edges in order of increasing weight without introducing cycles. Prim's algorithm finds the minimum spanning tree by growing a tree one vertex at a time, each time adding the edge with smallest weight that connects the growing tree to a new vertex. The document provides an example applying these algorithms.

Uploaded by

Sumit Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 10

Spanning Trees

Lecture 6 Maya M Ahmed NITK, Surathkal

Minimal weight Spanning tree

The weight of a graph is the sum of the weights of the edges of the graph. A spanning tree of G that has the smallest weight of all spanning trees of G is a minimum weight spanning tree.

Kruskals Algorithm also called Greedy Algorithm for nding minimum weight spanning tree

Let G = (V, E) be a weighted connected graph. 1. Put F = . 2. While there exists an edge e not in F such that F e does not contain a cycle, determine such an e of minimum weight and put e in F . 3. Put T = (V, F ).

a 1 b 5 c 5 1 d a 1 b 5 c 5 1 4 g 4 3 4 4 5 e 4 f 2 4 g 4 4 4 5 e 4 f 2

Prims Algorithm for a minimum-weight Spanning tree

Let G = (V, E) be a weighted connected graph. Let u be any vertex of G.

1. Put i = 1, U1 = {u}, F1 = , and T1 = (U1, F1).

2. For i = 1, 2, . . . , n 1, do the following: (a) Locate an edge xy of smallest weight such that x is in Ui and y is not in Ui. (b) Put Ui+1 = Ui {y}, Fi+1 = Fi xy, and Ti+1 = (Ui+1, Fi+1). (c) i = i + 1.
4

a 1 b 5 c 5 1 d 4 g 4 3 4 5 e 4 4 f 2

Quiz

a 1 2 g

3 1

b 2

1 3 2 1 e 2 d h 3

Find a minimum weight spanning trees using the Greedy Algorithm and Prims Algorithm. Find the distance tree for a using Dijsktras Algorithm.

Quiz Solution: Greedy Algorithm

a 1 2 g

3 1

b 2

1 3 2 1 e 2 d h 3

The edges are chosen in the following order: ag, bg, ch, he, ef , ed, af , The weight of the spanning tree is 10.

Quiz Solution: Prims Algorithm

a 1 2 g

3 1

b 2

1 3 2 1 e 2 d h 3

The edges are chosen in the following order: ag, gb, bh, he, hc, ed, ef , The weight of the spanning tree is 10. The weight of the spanning tree is 10.
8

Quiz Solution: Dijsktras Algorithm


4 c

0 a 1 2

3 1 1 g 2 3

2 b 2

1 h 1 e 3 2 d 5 4 3

f 2

The edges are chosen in the following order: ag, gb, bh, he, hc, ed, ef , The weight of this spanning tree is 12 and not minimum.
9

You might also like