minimum spanning trees

18
Minimum spanning trees

Upload: meriel

Post on 19-Jan-2016

18 views

Category:

Documents


0 download

DESCRIPTION

Minimum spanning trees. Minimum Connector Algorithms. Kruskal’s algorithm Select the shortest edge in a network Select the next shortest edge which does not create a cycle Repeat step 2 until all vertices have been connected. Prim’s algorithm Select any vertex - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Minimum spanning trees

Minimum spanning trees

Page 2: Minimum spanning trees

Minimum Connector Algorithms

Kruskal’s algorithm

1. Select the shortest edge in a network

2. Select the next shortest edge which does not create a cycle

3. Repeat step 2 until all vertices have been connected

Prim’s algorithm

1. Select any vertex

2. Select the shortest edge connected to that vertex

3. Select the shortest edge connected to any vertex already connected

4. Repeat step 3 until all vertices have been connected

Page 3: Minimum spanning trees

A cable company want to connect five villages to their network which currently extends to the market town of Avonford. What is the minimum length of cable needed?

Avonford Fingley

Brinleigh Cornwell

Donster

Edan

2

7

45

8 6 4

5

3

8

Example

Page 4: Minimum spanning trees

We model the situation as a network, then the problem is to find the minimum connector for the network

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 5: Minimum spanning trees

A F

B C

D

E

2

7

45

8 6 4

5

3

8

List the edges in order of size:

ED 2AB 3AE 4CD 4BC 5EF 5CF 6AF 7BF 8CF 8

Kruskal’s Algorithm

Page 6: Minimum spanning trees

Select the shortestedge in the network

ED 2

Kruskal’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 7: Minimum spanning trees

Select the next shortestedge which does notcreate a cycle

ED 2AB 3

Kruskal’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 8: Minimum spanning trees

Select the next shortestedge which does notcreate a cycle

ED 2AB 3CD 4 (or AE 4)

Kruskal’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 9: Minimum spanning trees

Select the next shortestedge which does notcreate a cycle

ED 2AB 3CD 4 AE 4

Kruskal’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 10: Minimum spanning trees

Select the next shortestedge which does notcreate a cycle

ED 2AB 3CD 4 AE 4BC 5 – forms a cycleEF 5

Kruskal’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 11: Minimum spanning trees

All vertices have beenconnected.

The solution is

ED 2AB 3CD 4 AE 4EF 5

Total weight of tree: 18

Kruskal’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 12: Minimum spanning trees

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Select any vertex

A

Select the shortest edge connected to that vertex

AB 3

Prim’s Algorithm

Page 13: Minimum spanning trees

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Select the shortestedge connected to any vertex already connected.

AE 4

Prim’s Algorithm

Page 14: Minimum spanning trees

Select the shortestedge connected to any vertex already connected.

ED 2

Prim’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 15: Minimum spanning trees

Select the shortestedge connected to any vertex already connected.

DC 4

Prim’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 16: Minimum spanning trees

Select the shortestedge connected to any vertex already connected.

CB 5 – forms a cycle

EF 5

Prim’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

Page 17: Minimum spanning trees

Prim’s Algorithm

A F

B C

D

E

2

7

45

8 6 4

5

3

8

All vertices have beenconnected.

The solution is

ED 2AB 3CD 4 AE 4EF 5

Total weight of tree: 18

Page 18: Minimum spanning trees

•Both algorithms will always give solutions with the same length.

•They will usually select edges in a different order – you must show this in your workings.

•Occasionally they will use different edges – this may happen when you have to choose between edges with the same length. In this case there is more than one minimum connector for the network.

Some points to note