Minimum Spanning Tree (MST) Algorithm: Kruskal's Algorithm and Cut Property, Study notes of Algorithms and Programming

The minimum spanning tree (mst) problem in computer science, focusing on kruskal's algorithm and the cut property. The mst problem aims to build a communication network with the cheapest cost, given a set of computers and maintenance costs for potential links. Kruskal's algorithm builds a spanning tree by successively adding edges in order of increasing weights without forming a cycle with previously chosen edges.

Typology: Study notes

Pre 2010

Uploaded on 08/05/2009

koofers-user-bf4
koofers-user-bf4 šŸ‡ŗšŸ‡ø

8 documents

1 / 47

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Design and analysis of algorithms
Lecture 18 & 19
Edyta Szyma“
nska
CS3510 A, Fall 2005 – p. 1/??
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f

Partial preview of the text

Download Minimum Spanning Tree (MST) Algorithm: Kruskal's Algorithm and Cut Property and more Study notes Algorithms and Programming in PDF only on Docsity!

Design and analysis of algorithms

Lecture 18 & 19^ Edyta Szyma Ā“

nska [email protected]

CS3510 A, Fall 2005 – p. 1/

Minimum spanning tree (MST)

Problem:

given a set of computers and a maintenance cost associated with every potential link, build a communicationnetwork which is connected and has the cheapest cost.

CS3510 A, Fall 2005 – p. 2/

Minimum spanning tree (MST)

Problem:

given a set of computers and a maintenance cost associated with every potential link, build a communicationnetwork which is connected and has the cheapest cost.^34 B

1 4 4

2

4 6

5 C^

E F

A

D Observation:

the optimal set of edges cannot contain a cycle.

CS3510 A, Fall 2005 – p. 2/

Minimum spanning tree (MST)

Problem:

given a set of computers and a maintenance cost associated with every potential link, build a communicationnetwork which is connected and has the cheapest cost.^34 B

1 4 4

2

4 6

5 C^

E F

A

D Observation:

the optimal set of edges cannot contain a cycle.Thus, the solution must be connected and acyclic -

TREE

CS3510 A, Fall 2005 – p. 2/

Minimum spanning tree (MST)

INPUT: an undirected, connected graph

G^ = (

V, E)

with edge weights

w(e)

OUTPUT: a tree

T^ = (

′V, E

)^ spanning all the vertices of

G^ and

minimizing weight

(T^ ) =

āˆ‘ ′ e∈E w(e)

(^34) B 1 4 4

2

4 6

5 C^

E F

A

D MST cost in the example above is 16.

CS3510 A, Fall 2005 – p. 3/

Minimum spanning tree (MST)

INPUT: an undirected, connected graph

G^ = (

V, E)

with edge weights

w(e)

OUTPUT: a tree

T^ = (

′V, E

)^ spanning all the vertices of

G^ and

minimizing weight

(T^ ) =

āˆ‘ ′ e∈E w(e)

(^34) B 1 4 4

2

4 6

5 C^

E F

A

D MST cost in the example above is 16.

CS3510 A, Fall 2005 – p. 3/

Minimum spanning tree (MST)

INPUT: an undirected, connected graph

G^ = (

V, E)

with edge weights

w(e)

OUTPUT: a tree

T^ = (

′V, E

)^ spanning all the vertices of

G^ and

minimizing weight

(T^ ) =

āˆ‘ ′ e∈E w(e)

(^34) B 1 4 4

2

4 6

5 C^

E F

A

D MST cost in the example above is 16. Is it unique?

CS3510 A, Fall 2005 – p. 3/

Greedy approach

Algorithms?

CS3510 A, Fall 2005 – p. 4/

Greedy approach

Algorithms? "Greed ... is good. Greed is right. Greed works." Kruskal’s greedy algorithm: build a spanning tree by successively adding edges inorder of increasing weights and in such a way that they donot form a cycle with those edges already chosen.

CS3510 A, Fall 2005 – p. 4/

Greedy approach

Algorithms? "Greed ... is good. Greed is right. Greed works." Kruskal’s greedy algorithm: build a spanning tree by successively adding edges inorder of increasing weights and in such a way that they donot form a cycle with those edges already chosen. See example on the board.

CS3510 A, Fall 2005 – p. 4/

Why is Kruskal’s algorithm correct?

We will proof a more general property first:

CS3510 A, Fall 2005 – p. 5/

Why is Kruskal’s algorithm correct?

Cut property:

Let^ X

āŠ†^ E

be part of some minimum spanning tree

T

of^ G^

= (V, E

).^ Pick any set of nodes

S^ āŠ‚

V^ such that there is no

edge in

X^ which connects a node in

S^ to one in

V^ ^

S.^ If^ e

∈^ E

is the

minimum-weight edge between

S^ and

V^ āˆ’

S,^ then

X^ ∪ {

e}^ is also

part of some MST.

CS3510 A, Fall 2005 – p. 5/

Why is Kruskal’s algorithm correct?

Proof:

Assume

e /∈^ T.^ Then

T^ ∪ {

e}^ contains a cycle

C.

Now

C^ contains another edge

′^ eacross the cut

(S, V

^ S)

e e’ S^

V^ ^ S

CS3510 A, Fall 2005 – p. 6/

Why is Kruskal’s algorithm correct?

Proof:

Assume

e /∈^ T.^ Then

T^ ∪ {

e}^ contains a cycle

C.

Now

C^ contains another edge

′^ eacross the cut

(S, V

^ S)

e e’ S^

V^ ^ S

Consider

′^ T =

T^ ∪ {

e} āˆ’ {

′′e}.It is a tree with

′ w(T ) =^ w

(T^ ) +

w(e)

āˆ’^ w

′(e)^ ≤ w(T

),^ because

w(e)

≤^ w

′(e).^ Since

T^ is MST, so is

′ T.

CS3510 A, Fall 2005 – p. 6/