+ All Categories
Home > Documents > Minimum Spanning Trees. a b d f g e c a b d f g e c.

Minimum Spanning Trees. a b d f g e c a b d f g e c.

Date post: 22-Dec-2015
Category:
View: 221 times
Download: 1 times
Share this document with a friend
Popular Tags:
39
Minimum Spanning Trees
Transcript
Page 1: Minimum Spanning Trees. a b d f g e c a b d f g e c.

Minimum Spanning Trees

Page 2: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

Page 3: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

Page 4: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

Page 5: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

Page 6: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

Minimum spanning tree weight = 0

Page 7: Minimum Spanning Trees. a b d f g e c a b d f g e c.

Systematic Approach:

-Grow a spanning tree A

-Always add a safe edge to A that we know belongs to some minimal spanning tree

Page 8: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R

Page 9: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R

There must go exactly one edge from b to the minimum spanning tree. Which edge should we choose?Are all three a possibility (maybe suboptimal)?Could the 7 edge be optimal to choose?What about the two 5 edges?

Page 10: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R

There must go exactly one edge from b to the spanning tree. Which edge should we choose?Are all three a possibility? Yes, every vertex will connect to the tree Could the 7 edge be optimal to choose? No, we must connect with a light edgeWhat about the two 5 edges? The red is possible, but they both are !!

Page 11: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R’

Page 12: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R’

Page 13: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R’

Page 14: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R’

Page 15: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R’

Page 16: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R’

Page 17: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R’

Page 18: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R’

Page 19: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R’’

Page 20: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R’’

Page 21: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R’’’

Page 22: Minimum Spanning Trees. a b d f g e c a b d f g e c.

Kruskal’s Algorithm

Page 23: Minimum Spanning Trees. a b d f g e c a b d f g e c.

Idea:

Rethink the previous algorithm from vertices to edges

-Initially each vertex forms a singleton tree

-In each iteration add the lightest edge connecting two trees in the forest.

Page 24: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

Page 25: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

Page 26: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

Page 27: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

Page 28: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

Page 29: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

Page 30: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

Page 31: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

Page 32: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

0

5

-1

8

0

R’’’

Page 33: Minimum Spanning Trees. a b d f g e c a b d f g e c.

MSTkruskal(G,w)

1 A Ø

2 for each vertex v V[G]

3 do MakeSet(v)

4 sort the edges of E into nondecreasing order by weight w

5 for each edge (u,v) E, taken in nondecreasing order by weight

6 do if FindSet(u) FindSet(v)

7 then A A {(u,v)}

8 Union(u,v)

9 return A

Page 34: Minimum Spanning Trees. a b d f g e c a b d f g e c.

MSTkruskal(G,w)

1 A Ø

2 for each vertex v V[G]

3 do MakeSet(v)

4 sort the edges of E into nondecreasing order by weight w

5 for each edge (u,v) E, taken in nondecreasing order by weight

6 do if FindSet(u) FindSet(v)

7 then A A {(u,v)}

8 Union(u,v)

9 return A

Time?

Page 35: Minimum Spanning Trees. a b d f g e c a b d f g e c.

MSTkruskal(G,w)

1 A Ø

2 for each vertex v V[G]

3 do MakeSet(v)

4 sort the edges of E into nondecreasing order by weight w

5 for each edge (u,v) E, taken in nondecreasing order by weight

6 do if FindSet(u) FindSet(v)

7 then A A {(u,v)}

8 Union(u,v)

9 return A

Time?

O(E*lgE)

Page 36: Minimum Spanning Trees. a b d f g e c a b d f g e c.

MSTkruskal(G,w)

1 A Ø

2 for each vertex v V[G]

3 do MakeSet(v)

4 sort the edges of E into nondecreasing order by weight w

5 for each edge (u,v) E, taken in nondecreasing order by weight

6 do if FindSet(u) FindSet(v)

7 then A A {(u,v)}

8 Union(u,v)

9 return A

Time?

O(E*lgE)

Theorem 21.13: m FindSet, Union, and MakeSet operations of which n are MakeSet operations takes O(m*α(n))

Page 37: Minimum Spanning Trees. a b d f g e c a b d f g e c.

MSTkruskal(G,w)

1 A Ø

2 for each vertex v V[G]

3 do MakeSet(v)

4 sort the edges of E into nondecreasing order by weight w

5 for each edge (u,v) E, taken in nondecreasing order by weight

6 do if FindSet(u) FindSet(v)

7 then A A {(u,v)}

8 Union(u,v)

9 return A

Time?

O(E*lg(E))

O(V+E*α(V)) =O(V+E*lg(V)) = O(V+E*lg(E)) =O(E*lg(E))

Page 38: Minimum Spanning Trees. a b d f g e c a b d f g e c.

MSTkruskal(G,w)

1 A Ø

2 for each vertex v V[G]

3 do MakeSet(v)

4 sort the edges of E into nondecreasing order by weight w

5 for each edge (u,v) E, taken in nondecreasing order by weight

6 do if FindSet(u) FindSet(v)

7 then A A {(u,v)}

8 Union(u,v)

9 return A

O(E*lg(E))

O(E*lg(E))

O(V+E*α(V)) =O(V+E*lg(V)) = O(V+E*lg(E)) =O(E*lg(E))

Page 39: Minimum Spanning Trees. a b d f g e c a b d f g e c.

a

b

d

f g

e

c

0

2

-3

-1

5

5

7

1

5

-1

8

0

R

Obviously tree. Which edge should we choose?


Recommended