1 NETWORK PN NORIZAH BT AHMAD
8/2/2019 Kruskal_s2009
http://slidepdf.com/reader/full/kruskals2009 1/41
1
NETWORK
PN NORIZAH BT AHMAD
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.
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.
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.
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.
8/2/2019 Kruskal_s2009
http://slidepdf.com/reader/full/kruskals2009 6/41
6
The Minimum-ConnectorProblem
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
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.
8/2/2019 Kruskal_s2009
http://slidepdf.com/reader/full/kruskals2009 9/41
9
The Minimum-ConnectorProblem
•Kruskal’s Algorithm
•Prim’s Algorithm
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
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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
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
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
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
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
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
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
8/2/2019 Kruskal_s2009
http://slidepdf.com/reader/full/kruskals2009 29/41
29
Example 2
• Find the minimal Spanning Tree
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
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
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
8/2/2019 Kruskal_s2009
http://slidepdf.com/reader/full/kruskals2009 33/41
33
Solution
• Select CF
2 3
3
2
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
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
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.
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
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
8/2/2019 Kruskal_s2009
http://slidepdf.com/reader/full/kruskals2009 39/41
39
Solution
• The solution can be shown in the diagram below.
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