kruskals prims shared by: geekssay.com

18
Minimum spanning trees

Upload: hemant-gautam

Post on 24-Jun-2015

446 views

Category:

Education


0 download

DESCRIPTION

Minimum Spanning trees presentation by: The University of Auckland(Faculty of Education)

TRANSCRIPT

Page 1: Kruskals prims shared by: geekssay.com

Minimum spanning trees

Page 2: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

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: Kruskals prims shared by: geekssay.com

•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