Top Banner
1 NETWORK  PN NORIZAH BT AHMAD
41

Kruskal_s2009

Apr 06, 2018

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 1/41

1

NETWORK 

PN NORIZAH BT AHMAD

Page 2: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 2/41

2

Network 

• A graph in which each edge (orarc) is given a value called itsweight.

• The weight on an edge mayrepresent a distance, a time ora cost.

• A graph also called asweighted graph.

Page 3: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 3/41

3

Example

• If we add distances to our route map theresulting network would look like this.

Page 4: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 4/41

4

MINIMAL SPANNING TREE (MST) (or 

MINIMUM CONNECTOR)

• To make a selection of the available arcs

• So, any node can be reached from anyother node such that the total length of the chosen arcs or edges is as small aspossible

•  A connected set of arcs with no loops iscalled a tree

• The set which solves the minimalconnector problem is called minimalspanning tree for the network.

Page 5: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 5/41

5

APPLICATION OF MINIMAL SPANNING

TREE

(1) Design of network – example: telephone networks

- To determine the least costly paths with no cycles inthis network, therefore connecting everyone at a

minimum cost

(2) Airline routes- vertices represent cities and edgesrepresent routes between the cities

- MST can be applied to optimize airlines routes byfinding the least costly paths with no cycles

(3) cable TV companies – to connect each town in some wayto the base station to received the signal but usingminimum cable.

Page 6: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 6/41

6

The Minimum-ConnectorProblem

Page 7: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 7/41

7

The Minimum-ConnectorProblem

Example

If A, B and F are linked as shown inthe figure below, B is already

connected to F via A so it isunnecessary to choose arc BF.

 A

B

F

Page 8: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 8/41

8

There are two ideas

• Kruskal’s and Prim’s Algorithmsto find the minimal spanningtree (The Minimum-Connector

Problem) of a weighted graph.• Dijkstra’s Algorithm to find the

shortest or least value path

between two nodes on aweighted graph.

Page 9: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 9/41

9

The Minimum-ConnectorProblem

•Kruskal’s Algorithm

•Prim’s Algorithm

Page 10: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 10/41

• KRUSKAL’S ALGORITHM

10

Page 11: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 11/41

11

Kruskal’s algorithmn

• choose the smallest availableedges.

• not worrying about any connection

to edges that have already beenchosen

• except that it is careful not to form

a cycle

Page 12: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 12/41

INTRODUCTION

• Kruskal's algorithm is an algorithm ingraph theory to find a minimum spanning tree for 

a connected weighted graph.

• This means it finds a subset of the edges that

forms a tree that includes every vertex, wherethe total weight of all the edges in the tree is

minimized.

Page 13: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 13/41

INTRODUCTION

• If the graph is not connected, then it finds aminimum spanning forest (a minimum spanning

tree for each connected component).

• Kruskal's algorithm is an example of a greedy

algorithm.

Page 14: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 14/41

14

The algorithm can be stated likethis :

• Step 1 – Sort the edges in ascending orderof length / weight.

• Step 2 – Select the shortest edges in thenetwork.

• Step 3 – Select, from the edges which arenot in the solution, the shortest edgeswhich does not form a cycle. (Where twoedges have the same weight, select at

random)

• Step 4 – Repeat step 3 until all the verticesare in the solution or form a spanning tree.

Page 15: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 15/41

STEPS IN FINDING MST

STEP 1

This is our original

graph. The numbersnear the arcsindicate their weight.None of the arcs arehighlighted.

Page 16: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 16/41

STEP 2

AD and CE are the

shortest arcs, withlength 5, and AD has been arbitrarilychosen, so it ishighlighted.

Page 17: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 17/41

STEP 3

However, CE isnow the shortestarc that does not

form a loop, withlength 5, so it ishighlighted as thesecond arc.

Page 18: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 18/41

STEP 4

The next arc,DF with length6, is highlightedusing much thesame method

Page 19: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 19/41

STEP 5

The next-shortest arcsare AB and BE, bothwith length 7. AB ischosen arbitrarily, andis highlighted. The arcBD has beenhighlighted in red,because it would forma loop ABD if it werechosen.

Page 20: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 20/41

STEP 6

The process continues to highlightthe next-smallest arc, BE withlength 7. Many more arcs arehighlighted in red at this stage: BC because it would form the loopBCE, DE because it would form

the loop DEBA, and FE because itwould form FEBAD.

Page 21: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 21/41

STEP 7

Finally, the

processfinishes withthe arc EG of length 9, andthe minimum

spanning treeis found.

Page 22: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 22/41

22

Example 1

• Use Kruskal’s algorithm to obtain a minimumspanning tree for this network.

 A

8

B

D

C

E5

6

7

4

1

3

Page 23: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 23/41

23

STEP 1 – Sort the edges inascending order of weights

Weight Edge

1 EC

3 EB

4 BC

5 AD

6 ED

7 CD

8 AB

Page 24: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 24/41

24

STEP 2 – Select the edge of leastweight

• The edge of least weight is edge EC.

 A

8

B

D

C

E5

7

4

1

3

Page 25: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 25/41

25

Step 3 – select the edge of leastweight that does not form a cyclewith the edges already included

• The edge of smallest weight available is edgeEB.

 A

8

B

D

C

E5

6

7

4

1

3

Page 26: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 26/41

26

• The edge of smallest weight available is edgeBC. However, this would form a cycle. So it is

not chosen.

• Choose edge AD.

 A8

B

D

C

E5

67

4

1

3

Page 27: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 27/41

27

• The smallest edge is now DE.

 A

B

D

C

E5

6

1

3

Page 28: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 28/41

28

•  All vertices are now in the solution and form aminimum spanning tree.

•  A total weight = 6 + 5 + 3 + 1 = 15

 A

B

D

C

E5

6

1

3

Page 29: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 29/41

29

Example 2

• Find the minimal Spanning Tree

Page 30: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 30/41

30

Solution

• Arcs (edges) ranked in order of increasinglength.

Length Arc/Edge

 ________________________________________ 2 AB, DE

3 DF, CF

4 EF5 AF, CD

6 AE, BF

8 BC

Page 31: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 31/41

31

Solution

• We can start by selecting AB or DE,so let us arbitrarily select AB.

• Select DE

B

2

2

2

Page 32: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 32/41

32

Solution

• We can select CF or DF, so let usarbitrarily select DF.

2

3

2

Page 33: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 33/41

33

Solution

• Select CF

2 3

3

2

Page 34: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 34/41

34

Solution

•  The next shortest arc is EF but E and F arealready connected via D, so we do notselect EF.

•  The next shortest arcs are CD and AF but

C and D are already connected via F, sowe choose AF

2

5

3

3

2

Page 35: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 35/41

35

Solution

• The minimal spanning trees is2 + 2 + 3 + 3 + 5 = 15

Page 36: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 36/41

36

Example 3

Use Kruskal’s algorithm to find the leastamount of cable needed to solve theproblem below.

Page 37: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 37/41

37

Solution

• First, rank the edges in order of length.Halifax to Huddersfield 8

Halifax to Bradford 10

Bradford to Leeds 12Bradford to Huddersfield 12

Leeds to Wakefield 13

Huddersfield to Wakefield 14Bradford to Wakefield 15

Leeds to Harrogate 20

Page 38: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 38/41

38

Solution

• Now we begin to select edges,starting with the smallest.

• We have now connected all the

vertices into the spanning tree.• The length of our minimum

spanning tree is 8 + 10 + 12 + 13+ 19 = 62 miles

Page 39: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 39/41

39

Solution

• The solution can be shown in the diagram below.

Page 40: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 40/41

40

ISL

• Reading - Decision Mathematics D1 pg 60 – 65

• Self – assessment exercise 3A pg 66 No 1 & 2

Th k f

Page 41: Kruskal_s2009

8/2/2019 Kruskal_s2009

http://slidepdf.com/reader/full/kruskals2009 41/41

41

Thank you for yourattention

Can we proceed to anothersubtopic ?

Prim’s Algorithm to find another

MST.