Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

MATH1800 Mathematical Modelling

School of Mathematical and Physical Sciences, Faculty of Science and Information Technology, University of Newcastle, Australia

Semester 2

Lec 7

Network Models
A Network is an interconnected system of objects.
For example,
Social network (facebook, myspace, linkedin, etc.) Communication network (internet, mobile network, wireless network, etc) Neural networks Electricity network Transportation network Supply chain network

Lec 7

Network Models

Electricity networks Network models can help with:


Modelling system capacity Understanding failure rates Making system more robust Analysing connectivity Making decisions regarding infrastructure/technology investment

www.smartgridaustralia.com.au www.climatechange.gov.au

Lec 7

Network Models

Supply chain networks


Mining (HVCC) Retail (Kmart) Fresh food (Coles/Woolies) Auto manufacturing (Ford Co. Push Vs Pull) Technology (Dell: Just in time)

Network models can help with:


Identifying inefficiencies Finding system capacity/bottlenecks Modelling flow rate of product through system Decision making regarding infrastructure/technology investment

Lec 7

Network Models

Neural networks Network models can help with:


Understanding the process of cognition Studying degenerative diseases Designing adaptive systems and artificial intelligence (learning) Computer science

Biology

Lec 7

Network Models

Communication networks

Network models can help with:


Efficient routing Identifying bandwidth capacity/bottlenecks Network design (hub-and-spoke Vs all-to-all) Decision making regarding infrastructure/technology investment Identifying security vulnerabilities

Lec 7

Network Models
Network models can help with:
Efficient routing (multi modal) Identifying flow capacity/bottlenecks Analysing connectivity Decision making regarding Infrastructure investment

Transportation networks

Lec 7

Network Models

Social networks

Network models can help with:


Analysing connectivity/visibility Efficient sharing/dissemination of information Protecting private information

Lec 7

Network Models
A Network is an interconnected system of objects.
For example,
Social network (facebook, myspace, linkedin, etc.) Communication network (internet, mobile network, wireless network, etc) Neural networks Electricity network Transportation network Supply chain network

Lec 7

Network Models
A Network is an interconnected system of objects.
For example,
Social network (facebook, myspace, linkedin, etc.) Communication network (internet, mobile network, wireless network, etc) Neural networks Electricity network Transportation network Supply chain network

Intuitive, natural paradigm for thinking about many real problems Special properties Extremely fast and efficient algorithms/techniques available Large scale problems can be solved We will look at:
Spanning trees Shortest paths Network Flows Maximum Flow Minimum Cost Flow (time permitting)

Lec 7

Network Models: Terms and Notation

2 1 3 4 7 8 5

6 9 10

N = set of nodes or vertices

Lec 7

Network Models: Terms and Notation


Graph
2 1 3 4 7 8 5 10 6 9

N = set of nodes or vertices A = set of edges or arcs or links i, j are nodes in N


i j

{i, j}
Undirected edge Unordered node pair

Graph = (N, A)

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

N = set of nodes or vertices A = set of edges or arcs or links i, j are nodes in N


i j i j

(i, j)
Directed edge Ordered node pair

{i, j}
Undirected edge Unordered node pair

Digraph = (N, A) where A consists of directed edges

Graph = (N, A)

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

N = {1,2,3,,10} A = {(1,3), (2,1), (3,2), (3,8), (4,2), (4,3), (4,5), }

N = {1,2,3,,10} A = {{1,3}, {2,1}, {3,2}, {3,8}, {4,2}, {4,3}, {4,5}, }

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

N = {1,2,3,,10} A = {(1,3), (2,1), (3,2), (3,8), (4,2), (4,3), (4,5), }

N = {1,2,3,,10} A = {{1,3}, {2,1}, {3,2}, {3,8}, {4,2}, {4,3}, {4,5}, }

Q. What are some other types of information that could be useful in network modelling? Arc costs: cij is the cost associated with arc (i,j) or edge {i,j} Arc/node capacities

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

N = {1,2,3,,10} A = {(1,3), (2,1), (3,2), (3,8), (4,2), (4,3), (4,5), }

N = {1,2,3,,10} A = {{1,3}, {2,1}, {3,2}, {3,8}, {4,2}, {4,3}, {4,5}, }

Q. What are some interesting components of a graph/digraph? Path: sequence of nodes connected by edges/arcs Directed and undirected paths in digraphs

Cycle: path that starts and ends at the same node Directed and undirected cycles in digraphs

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

Directed path N = {1,2,3,,10} A = {(1,3), (2,1), (3,2), (3,8), (4,2), (4,3), (4,5), } N = {1,2,3,,10}

Undirected path

A = {{1,3}, {2,1}, {3,2}, {3,8}, {4,2}, {4,3}, {4,5}, }

Path: sequence of nodes connected by edges/arcs


A directed path from 1 to 9 is: (1, 3, 8, 7, 10, 6 , 9) A path from 1 to 9 is: (1, 3, 8, 7, 10, 6 , 9)

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

Directed path N = {1,2,3,,10} A = {(1,3), (2,1), (3,2), (3,8), (4,2), (4,3), (4,5), } N = {1,2,3,,10}

Undirected path

A = {{1,3}, {2,1}, {3,2}, {3,8}, {4,2}, {4,3}, {4,5}, }

Path: sequence of nodes connected by edges/arcs


A directed path from 1 to 9 is: (1, 3, 8, 7, 10, 6 , 9) Another directed path from 1 to 9 is: (1, 3, 8, 7, 4, 5, 10, 6, 9) A path from 1 to 9 is: (1, 3, 8, 7, 10, 6 , 9) Another path from 1 to 9 is: (1, 3, 8, 7, 4, 5, 10, 6, 9)

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

Undirected path N = {1,2,3,,10} A = {(1,3), (2,1), (3,2), (3,8), (4,2), (4,3), (4,5), } N = {1,2,3,,10}

Undirected path

A = {{1,3}, {2,1}, {3,2}, {3,8}, {4,2}, {4,3}, {4,5}, }

Path: sequence of nodes connected by edges/arcs


A directed path from 1 to 9 is: (1, 3, 8, 7, 10, 6 , 9) Another directed path from 1 to 9 is: (1, 3, 8, 7, 4, 5, 10, 6, 9) An undirected path from 1 to 9 is: (1, 2, 4, 6, 9) A path from 1 to 9 is: (1, 3, 8, 7, 10, 6 , 9) Another path from 1 to 9 is: (1, 3, 8, 7, 4, 5, 10, 6, 9) Yet another path from 1 to 9 is: (1, 2, 4, 6, 9)

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

Directed cycle N = {1,2,3,,10} A = {(1,3), (2,1), (3,2), (3,8), (4,2), (4,3), (4,5), } N = {1,2,3,,10}

Undirected cycle

A = {{1,3}, {2,1}, {3,2}, {3,8}, {4,2}, {4,3}, {4,5}, }

Cycle: path that starts and ends at the same node


A directed cycle is: (4, 5, 7, 4) A cycle is: (4, 5, 7, 4)

10

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

Directed cycle N = {1,2,3,,10} A = {(1,3), (2,1), (3,2), (3,8), (4,2), (4,3), (4,5), } N = {1,2,3,,10}

Undirected cycle

A = {{1,3}, {2,1}, {3,2}, {3,8}, {4,2}, {4,3}, {4,5}, }

Cycle: path that starts and ends at the same node


A directed cycle is: (4, 5, 7, 4) Another directed cycle is: (2, 1, 3, 8, 7, 4, 2) A cycle is: (4, 5, 7, 4) Another cycle is: (2, 1, 3, 8, 7, 4, 2)

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

Undirected cycle N = {1,2,3,,10} A = {(1,3), (2,1), (3,2), (3,8), (4,2), (4,3), (4,5), } N = {1,2,3,,10}

Undirected cycle

A = {{1,3}, {2,1}, {3,2}, {3,8}, {4,2}, {4,3}, {4,5}, }

Cycle: path that starts and ends at the same node


A directed cycle is: (4, 5, 7, 4) Another directed cycle is: (2, 1, 3, 8, 7, 4, 2) An undirected cycle is: (4, 6, 9, 10, 7, 4) A cycle is: (4, 5, 7, 4) Another cycle is: (2, 1, 3, 8, 7, 4, 2) Yet another cycle is: (4, 6, 9, 10, 7, 4)

11

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

Q. What are some interesting characteristics of a graph/digraph? Acyclic: does not contain any (directed) cycles

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

Acyclic

Acyclic

2 1 3 4 7 8 5

6 9 10 1

2 4 3 7 8 5

6 9 10

Cyclic

Cyclic

12

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

Q. What are some interesting characteristics of a graph/digraph? Acyclic: does not contain any (directed) cycles Connected: there is a path from each node to every other node A directed path from each node to every other node in digraph: Strongly connected An undirected path from each node to every other node in digraph : Weakly connected

Lec 7

Network Models: Terms and Notation


Digraph (Network)
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Graph
6 9

Weakly connected

Disconnected

2 1 3 4 7 8 5

6 9 10 1

2 4 3 7 8 5

6 9 10

Strongly connected

Connected

13

Lec 7

Network Models: Trees in Undirected Graphs


Undirected Graph
2 1 3 4 7 8 5 10 6 9

Tree

Tree
An undirected graph is a Tree if it is connected and acyclic

Lec 7

Network Models: Trees in Undirected Graphs

Examples of Trees:
2 1 3 4 7 8 5 10 Tree 6 9 2 3 Tree 8 1 4 5 6 2 1 7 6 Tree 3 4 2 5 1 3 7 8 Tree 4 5 6

Tree
An undirected graph is a Tree if it is connected and acyclic

Q. Why are the following examples not Trees:


2 1 3 4 7 8 5 10 6 9 2 3 8 1 4 5 6 2 1 7 6 3 4 2 5 1 3 7 8 4 5 6

14

Lec 7

Network Models: Trees in Undirected Graphs

Examples of Trees:
2 1 3 4 7 8 5 10 Tree 6 9 2 3 Tree 8 1 4 5 6 2 1 7 6 Tree 3 4 2 5 1 3 7 8 Tree 4 5 6

Tree
An undirected graph is a Tree if it is connected and acyclic

Q. Why are the following examples not Trees:


2 1 3 4 7 8 Disconnected Cyclic 5 10 6 9 2 3 8 1 4 5 6 2 1 6 7 Disconnected 3 4 2 5 1 3 7 8 Cyclic 4 5 6

Lec 7

Network Models: Trees in Undirected Graphs

Examples of Trees:
2 1 3 4 7 8 10 nodes 9 edges 5 10 Tree 6 nodes 5 edges 6 9 2 3 Tree 1 4 5 6 2 1 6 8 7 Tree 8 nodes 7 edges 3 4 2 5 1 3 7 8 Tree 8 nodes 7 edges 4 5 6

Tree
An undirected graph is a Tree if it is connected and acyclic Q. Is it true that a tree with n nodes will have n-1 edges? A. Yes. (Why? Try drawing a tree with 4 nodes and 4 edges, 5 nodes and 5 edges, etc.
you will always get a cycle)

15

Lec 7

Network Models: Trees in Undirected Graphs

Examples of Trees:
2 1 3 4 7 8 10 nodes 9 edges 5 10 Tree 6 nodes 5 edges 6 9 2 3 Tree 1 4 5 6 2 1 8 7 Tree 8 nodes 7 edges 6 3 4 2 5 1 3 7 8 Tree 8 nodes 7 edges 4 5 6

Tree
An undirected graph is a Tree if it is connected and acyclic Q. Is it true that a tree with n nodes will have n-1 edges? A. Yes. (Why? Try drawing a tree with 4 nodes and 4 edges, 5 nodes and 5 edges, etc.
you will always get a cycle)

Q. Is it true that a graph with n nodes and n-1 edges is a tree?

Lec 7

Network Models: Trees in Undirected Graphs

Examples of Trees:
2 1 3 4 7 8 10 nodes 9 edges 5 10 Tree 6 nodes 5 edges 6 9 2 3 Tree 1 4 5 6 2 1 6 8 7 Tree 8 nodes 7 edges 3 4 2 5 1 3 7 8 Tree 8 nodes 7 edges 4 5 6

Tree
An undirected graph is a Tree if it is connected and acyclic Q. Is it true that a tree with n nodes will have n-1 edges? A. Yes. (Why? Try drawing a tree with 4 nodes and 4 edges, 5 nodes and 5 edges, etc.
you will always get a cycle)

Q. Is it true that a graph with n nodes and n-1 edges is a tree? A. No.
1 2 3 4

Q. Is it true that a connected graph with n nodes and n-1 edges is a tree?

16

Lec 7

Network Models: Trees in Undirected Graphs

Examples of Trees:
2 1 3 4 7 8 10 nodes 9 edges 5 10 Tree 6 nodes 5 edges 6 9 2 3 Tree 1 4 5 6 2 1 8 7 Tree 8 nodes 7 edges 6 3 4 2 5 1 3 7 8 Tree 8 nodes 7 edges 4 5 6

Tree
An undirected graph is a Tree if it is connected and acyclic Q. Is it true that a tree with n nodes will have n-1 edges? A. Yes. (Why? Try drawing a tree with 4 nodes and 4 edges, 5 nodes and 5 edges, etc.
you will always get a cycle)

Q. Is it true that a graph with n nodes and n-1 edges is a tree? A. No.
1 2 3 4

Q. Is it true that a connected graph with n nodes and n-1 edges is a tree? A. Yes.

Lec 7

Network Models: Spanning Trees in Undirected Graphs


Undirected Graph
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10

Subgraph
6 9

Spanning Tree

Tree
An undirected graph is a Tree if it is connected and acyclic

Spanning Tree
Some subset of nodes and arcs

A subgraph is a Spanning Tree if it is a tree that contains every node of the graph.

17

Lec 7

Network Models: Spanning Trees in Undirected Graphs


2 1 3 4 7 8 5 10 6 9

2 1 3 4 7 5

6 9 10 Subgraph 1 1

2 4 3 7 8 5

6 9 10 Subgraph 2 1

2 4 3 7 8 5

6 9 10 Subgraph 3

Subgraph is a tree but does not contain all nodes

Subgraph is not a tree (not connected)

Subgraph is not a tree (not acyclic)

Spanning Tree
A subgraph is a Spanning Tree if it is a tree that contains every node of the graph.

Lec 7

Network Models: Spanning Trees in Undirected Graphs


Undirected Graph Subgraph

2 1 3 4 7 8 5

6 9 10 1

2 4 3 7 8 5

6 9 10

Spanning Tree

Tree
An undirected graph is a Tree if it is connected and acyclic

Spanning Tree
A subgraph is a Spanning Tree if it is a tree that contains every node of the graph.

Minimum Spanning Tree (MST)


A Minimum Spanning Tree (MST) is a Spanning Tree whose cost (i.e. the sum of all edge costs of the tree) is the least among all spanning trees.

18

Lec 7

Network Models: Spanning Trees in Undirected Graphs

Exercise: Write down all the spanning trees of


1

1 3 3

4
2

edge cost

1 2 3

4 2

1 3

4 2

1 3

4 2

1 3

Cost = 8

Cost = 10

Cost = 8

Cost = 9

1 2 3

4 2

1 3

4 2

1 3

4 2

1 3

Cost = 7

Cost = 8

Cost = 6

Cost = 6

Lec 7

Network Models: Application of Spanning Trees


Broadband infrastructure planning
Every hub needs to be able to communicate with every other hub. What is the cheapest way of achieving this?

Nodes correspond to communication hubs Edges correspond to data links The cost of an edge corresponds to the cost associated with building that link

MST solution (why does a spanning tree give the optimal solution?)

19

Lec 7

Network Models: Application of Spanning Trees


Cluster analysis
Find clusters within data to draw inferences about possible relationships, correlations, cause and effects, etc. For example, a medical team has data on 350 patients that have a disease that is not well understood. 18 symptoms are measure for each patient. The medical team wants to know if they can develop a better understanding of the disease by categorizing the symptoms into smaller groupings.

Nodes represent patients Distance between nodes represents the similarities in symptoms

Lec 7

Network Models: Application of Spanning Trees


Cluster analysis
Find clusters within data to draw inferences about possible relationships, correlations, cause and effects, etc. For example, a medical team has data on 350 patients that have a disease that is not well understood. 18 symptoms are measure for each patient. The medical team wants to know if they can develop a better understanding of the disease by categorizing the symptoms into smaller groupings. MST

Nodes represent patients Distance between nodes represents the similarities in symptoms

20

Lec 7

Network Models: Application of Spanning Trees


Cluster analysis
Find clusters within data to draw inferences about possible relationships, correlations, cause and effects, etc. For example, a medical team has data on 350 patients that have a disease that is not well understood. 18 symptoms are measure for each patient. The medical team wants to know if they can develop a better understanding of the disease by categorizing the symptoms into smaller groupings.

Nodes represent patients Distance between nodes represents the similarities in symptoms

Longest edge

Lec 7

Network Models: Application of Spanning Trees


Cluster analysis
Find clusters within data to draw inferences about possible relationships, correlations, cause and effects, etc. For example, a medical team has data on 350 patients that have a disease that is not well understood. 18 symptoms are measure for each patient. The medical team wants to know if they can develop a better understanding of the disease by categorizing the symptoms into smaller groupings.

Nodes represent patients Distance between nodes represents the similarities in symptoms

Longest edge

Cluster 1

21

Lec 7

Network Models: Application of Spanning Trees


Cluster analysis
Find clusters within data to draw inferences about possible relationships, correlations, cause and effects, etc. For example, a medical team has data on 350 patients that have a disease that is not well understood. 18 symptoms are measure for each patient. The medical team wants to know if they can develop a better understanding of the disease by categorizing the symptoms into smaller groupings.
Cluster 2

Nodes represent patients


Longest edge

Distance between nodes represents the similarities in symptoms

Cluster 1

Lec 7

Network Models: Application of Spanning Trees


Cluster analysis
Find clusters within data to draw inferences about possible relationships, correlations, cause and effects, etc. For example, a medical team has data on 350 patients that have a disease that is not well understood. 18 symptoms are measure for each patient. The medical team wants to know if they can develop a better understanding of the disease by categorizing the symptoms into smaller groupings.
Cluster 3 Cluster 2

Nodes represent patients Distance between nodes represents the similarities in symptoms

Cluster 4

Cluster 1

22

Lec 7

Network Models: Application of Spanning Trees


Cluster analysis
Find clusters within data to draw inferences about possible relationships, correlations, cause and effects, etc.

Yahoo uses similar techniques to find latent structures within large complex data networks

Googles page rank. Facebooks friend, friend-of-friend network Linked in network

Lec 7

Network Models: Application of Spanning Trees


Data compression: storing records of similar data
For example, Storing sequence of amino acids in genetics Image compression Data storage/backup If data in each record is similar, then it could be more efficient to store the differences between the records rather than individual records

23

Lec 7

Network Models: Application of Spanning Trees


Data compression: storing records of similar data
For example, Storing sequence of amino acids in genetics Image compression Data storage/backup If data in each record is similar, then it could be more efficient to store the differences between the records rather than individual records For example, 4 records containing 5 pieces of information

R1 = a b c d e R2 = a f g d e e R3 = g b c f

R1R2 = b f, c g R1R3 = a g, d f R1R4 = b h R2R3 = a g, f b, g c, d f R2R4 = f h, g c R3R4 = g a, b h, f d

(2 differences) (2 differences) (1 difference) (4 differences) (2 differences) (3 differences)

R4 = a h c d e

Instead of storing 5x4=20 pieces of data. We store one record and the differences to other records.

Lec 7

Network Models: Application of Spanning Trees


Data compression: storing records of similar data
1
R1 R4 Each node corresponds to a record The cost of an edge {Ri,Rj} corresponds to the number of differences between records i and j

2 2 2
R2 R3

R1 = a b c d e R2 = a f g d e e R3 = g b c f

R1R2 = b f, c g R1R3 = a g, d f R1R4 = b h R2R3 = a g, f b, g c, d f R2R4 = f h, g c R3R4 = g a, b h, f d

(2 differences) (2 differences) (1 difference) (4 differences) (2 differences) (3 differences)

R4 = a h c d e

Note: A spanning tree tells us which differences to store. Hence we want MST

24

Lec 7

Network Models: Application of Spanning Trees


Data compression: storing records of similar data
From R1 we can obtain R2. From R2 we can obtain R3 and R4 . Spanning Tree requires storage of 5 + 2x(2 + 2 + 4) = 21 pieces of data

R1

R4

2 2
R2 R3

R1 = a b c d e R2 = a f g d e e R3 = g b c f

R1R2 = b f, c g R1R3 = a g, d f R1R4 = b h R2R3 = a g, f b, g c, d f R2R4 = f h, g c R3R4 = g a, b h, f d

(2 differences) (2 differences) (1 difference) (4 differences) (2 differences) (3 differences)

R4 = a h c d e

Note: A spanning tree tells us which differences to store. Hence we want MST

Lec 7

Network Models: Application of Spanning Trees


Data compression: storing records of similar data
From R1 we can obtain R2 and R3. From R3 we can obtain R4. Spanning Tree requires storage of 5 + 2x(2 + 2 + 3) = 19 pieces of data

R1

R4

2 2
R2 R3

R1 = a b c d e R2 = a f g d e e R3 = g b c f

R1R2 = b f, c g R1R3 = a g, d f R1R4 = b h R2R3 = a g, f b, g c, d f R2R4 = f h, g c R3R4 = g a, b h, f d

(2 differences) (2 differences) (1 difference) (4 differences) (2 differences) (3 differences)

R4 = a h c d e

Note: A spanning tree tells us which differences to store. Hence we want MST

25

Lec 7

Network Models: Application of Spanning Trees


Data compression: storing records of similar data
1
R1 R4 From R1 we can obtain R3 and R4. From R4 we can obtain R2. Spanning Tree requires storage of 5 + 2x(2 + 2 + 1) = 15 pieces of data

2 2
R2 R3

R1 = a b c d e R2 = a f g d e e R3 = g b c f

R1R2 = b f, c g R1R3 = a g, d f R1R4 = b h R2R3 = a g, f b, g c, d f R2R4 = f h, g c R3R4 = g a, b h, f d

(2 differences) (2 differences) (1 difference) (4 differences) (2 differences) (3 differences)

R4 = a h c d e

Note: A spanning tree tells us which differences to store. Hence we want MST

Lec 7

Network Models: Algorithms for MST


Prims Algorithm for MST (1957) 1. 2. 3. Select any node in the graph Connect this node to the nearest (lowest cost) node Considering all nodes that are now connected, find and connect the nearest node that is not connected. Break ties arbitrarily. Repeat third step until all nodes are connected

4.

26

Lec 7

Network Models: Algorithms for MST


Example: Using Prims Algorithm to find MST

2
2 3

3 5

5
7

1
5

7
2

3
3 2

6
6

Connected nodes Unconnected nodes Edges part of spanning tree Edges connecting connected nodes to unconnected nodes Edges connecting unconnected nodes Edges not part of spanning tree

Lec 7

Network Models: Algorithms for MST


Example: Using Prims Algorithm to find MST

2
2 3

3 5

5
7

Itera tion

Connected nodes 1

Unconnected nodes 2, 3, 4, 5, 6, 7, 8

Nearest connection {1,3}

1
5

7
2

3
3 2

6
6

Connected nodes Unconnected nodes Edges part of spanning tree Edges connecting connected nodes to unconnected nodes Edges connecting unconnected nodes Edges not part of spanning tree

27

Lec 7

Network Models: Algorithms for MST


Example: Using Prims Algorithm to find MST

2
2 3

3 5

5
7

Itera tion

Connected nodes 1 1, 3

Unconnected nodes 2, 3, 4, 5, 6, 7, 8 2, 4, 5, 6, 7, 8

Nearest connection {1,3} {3,4}

1
5

7
2

3
3 2

6
6

Connected nodes Unconnected nodes Edges part of spanning tree Edges connecting connected nodes to unconnected nodes Edges connecting unconnected nodes Edges not part of spanning tree

Lec 7

Network Models: Algorithms for MST


Example: Using Prims Algorithm to find MST

2
2 3

3 5

5
7

Itera tion

Connected nodes 1 1, 3 1, 3, 4

Unconnected nodes 2, 3, 4, 5, 6, 7, 8 2, 4, 5, 6, 7, 8 2, 5, 6, 7, 8

Nearest connection {1,3} {3,4} {3,2}

1
5

7
2

2 3

3
3 2

6
6

Connected nodes Unconnected nodes Edges part of spanning tree Edges connecting connected nodes to unconnected nodes Edges connecting unconnected nodes Edges not part of spanning tree

28

Lec 7

Network Models: Algorithms for MST


Example: Using Prims Algorithm to find MST

2
2 3

3 5

5
7

Itera tion

Connected nodes 1 1, 3 1, 3, 4 1, 3, 4, 2

Unconnected nodes 2, 3, 4, 5, 6, 7, 8 2, 4, 5, 6, 7, 8 2, 5, 6, 7, 8 5, 6, 7, 8

Nearest connection {1,3} {3,4} {3,2} {2,5}

1
5

7
2

2 3 4

3
3 2

6
6

Connected nodes Unconnected nodes Edges part of spanning tree Edges connecting connected nodes to unconnected nodes Edges connecting unconnected nodes Edges not part of spanning tree

Lec 7

Network Models: Algorithms for MST


Example: Using Prims Algorithm to find MST

2
2 3

3 5

5
7

Itera tion

Connected nodes 1 1, 3 1, 3, 4 1, 3, 4, 2 1, 3, 4, 2, 5

Unconnected nodes 2, 3, 4, 5, 6, 7, 8 2, 4, 5, 6, 7, 8 2, 5, 6, 7, 8 5, 6, 7, 8 6, 7, 8

Nearest connection {1,3} {3,4} {3,2} {2,5} {3,6}

1
5

7
2

2 3 4 5

3
3 2

6
6

Connected nodes Unconnected nodes Edges part of spanning tree Edges connecting connected nodes to unconnected nodes Edges connecting unconnected nodes Edges not part of spanning tree

29

Lec 7

Network Models: Algorithms for MST


Example: Using Prims Algorithm to find MST

2
2 3

3 5

5
7

Itera tion

Connected nodes 1 1, 3 1, 3, 4 1, 3, 4, 2 1, 3, 4, 2, 5 1, 3, 4, 2, 5, 6

Unconnected nodes 2, 3, 4, 5, 6, 7, 8 2, 4, 5, 6, 7, 8 2, 5, 6, 7, 8 5, 6, 7, 8 6, 7, 8 7, 8

Nearest connection {1,3} {3,4} {3,2} {2,5} {3,6} {6,8}

1
5

7
2

2 3 4 5

3
3 2

6
6

Connected nodes Unconnected nodes Edges part of spanning tree Edges connecting connected nodes to unconnected nodes Edges connecting unconnected nodes Edges not part of spanning tree

Lec 7

Network Models: Algorithms for MST


Example: Using Prims Algorithm to find MST

2
2 3

3 5

5
7

Itera tion

Connected nodes 1 1, 3 1, 3, 4 1, 3, 4, 2 1, 3, 4, 2, 5 1, 3, 4, 2, 5, 6 1, 3, 4, 2, 5, 6, 8

Unconnected nodes 2, 3, 4, 5, 6, 7, 8 2, 4, 5, 6, 7, 8 2, 5, 6, 7, 8 5, 6, 7, 8 6, 7, 8 7, 8 7

Nearest connection {1,3} {3,4} {3,2} {2,5} {3,6} {6,8} {8,7}

1
5

7
2

2 3 4 5

3
3 2

6
6

6 7

Connected nodes Unconnected nodes Edges part of spanning tree Edges connecting connected nodes to unconnected nodes Edges connecting unconnected nodes Edges not part of spanning tree

30

Lec 7

Network Models: Algorithms for MST


Example: Using Prims Algorithm to find MST

2
2 3

3 5

5
7

Itera tion

Connected nodes 1 1, 3 1, 3, 4 1, 3, 4, 2 1, 3, 4, 2, 5 1, 3, 4, 2, 5, 6 1, 3, 4, 2, 5, 6, 8 1, 3, 4, 2, 5, 6, 8, 7

Unconnected nodes 2, 3, 4, 5, 6, 7, 8 2, 4, 5, 6, 7, 8 2, 5, 6, 7, 8 5, 6, 7, 8 6, 7, 8 7, 8 7

Nearest connection {1,3} {3,4} {3,2} {2,5} {3,6} {6,8} {8,7}

1
5

7
2

2 3 4 5

3
3 2

6
6

6 7 8

Connected nodes Unconnected nodes Edges part of spanning tree Edges connecting connected nodes to unconnected nodes Edges connecting unconnected nodes Edges not part of spanning tree

Lec 7

Network Models: Algorithms for MST


Example: Using Prims Algorithm to find MST

2
2 3

3 5

5
7

MST has edges: {1,3}, {3,4}, {3,2}, {3,6}, {2,5}, {6,8}, and {8,7}, and cost 16

1
5

7
2

8 nodes and 7 edges.

3
3 2

6
6

Connected nodes Unconnected nodes Edges part of spanning tree Edges connecting connected nodes to unconnected nodes Edges connecting unconnected nodes Edges not part of spanning tree

31

Lec 7

Network Models: Algorithms for MST


Prims Algorithm for MST (1957) 1. 2. 3. Select any node in the graph Connect this node to the nearest (lowest cost) node Considering all nodes that are now connected, find and connect the nearest node that is not connected. Break ties arbitrarily. Repeat third step until all nodes are connected

4.

Q. Will this algorithm always construct a spanning tree? A. Yes. After choosing initial node in step 1, in each subsequent step we add one additional node and edge until all nodes are selected. Hence we have n nodes, and n-1 edges selected. Furthermore, the construction always connects an unconnected node to a connected node so the subgraph will also be connected. n nodes + n-1 edges + connected subgraph Spanning Tree.

Lec 7

Network Models: Algorithms for MST


Prims Algorithm for MST (1957) 1. 2. 3. Select any node in the graph Connect this node to the nearest (lowest cost) node Considering all nodes that are now connected, find and connect the nearest node that is not connected. Break ties arbitrarily. Repeat third step until all nodes are connected

4.

Q. Will this algorithm always construct a spanning tree? A. Yes. After choosing initial node in step 1, in each subsequent step we add one additional node and edge until all nodes are selected. Hence we have n nodes, and n-1 edges selected. Furthermore, the construction always connects an unconnected node to a connected node so the subgraph will also be connected. n nodes + n-1 edges + connected subgraph Spanning Tree. Q. Will this algorithm always construct a minimum spanning tree? A. Yes. Proof is not trivial. We will show this by examining certain properties of MST.

32

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


Definition of a Cut A cut is a subset of nodes S N. For undirected graphs, edges across a cut are edges that have one end is in S and the other end not in S. For directed graphs: arcs out a cut are arcs with tail in S and head not in S, and arcs into a cut are arcs with head in S and tail not in S.
Graph 2 1 3 4 7 8 5 10 6 9

e.g. S = {1, 2, 3 ,4} edges across cut: {4,5}, {4,6}, {3,8}, {7,4}

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


Definition of a Cut A cut is a subset of nodes S N. For undirected graphs, edges across a cut are edges that have one end is in S and the other end not in S. For directed graphs: arcs out a cut are arcs with tail in S and head not in S, and arcs into a cut are arcs with head in S and tail not in S.
Digraph (Network) 2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10 Graph 6 9

e.g. S = {1, 2, 3 ,4} arcs out of cut: (4,5), (4,6), (3,8) arcs into cut: (7,4)

e.g. S = {1, 2, 3 ,4} edges across cut: {4,5}, {4,6}, {3,8}, {7,4}

33

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


Definition of a Cut A cut is a subset of nodes S N. For undirected graphs, edges across a cut are edges that have one end is in S and the other end not in S. For directed graphs: arcs out a cut are arcs with tail in S and head not in S, and arcs into a cut are arcs with head in S and tail not in S.
Digraph (Network) 2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10 Graph 6 9

e.g. S = {1, 2, 3 ,4, 7, 8} arcs out of cut: (4,5), (4,6), (7,10) arcs into cut: (5,7)

e.g. S = {1, 2, 3 ,4, 7, 8} edges across cut: {4,5}, {4,6}, {7,5}, {7,10}

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


Definition of a Cut A cut is a subset of nodes S N. For undirected graphs, edges across a cut are edges that have one end is in S and the other end not in S. For directed graphs: arcs out a cut are arcs with tail in S and head not in S, and arcs into a cut are arcs with head in S and tail not in S.
Digraph (Network) 2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10 Graph 6 9

e.g. S = {1, 2, 3 ,4, 7, 8, 5, 6} e.g. S = {1, 2, 3 ,4, 7, 8, 5 ,6} arcs out of cut: (6,9), (6,10), (5,10), (7,10) edges across cut: {6,9}, {6,10}, {5,10}, {7,10} arcs into cut: (10,6)

34

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


Spanning Tree Property 1 Any edge in a spanning tree induces a cut in the graph: remove the edge and the spanning tree breaks into 2 disconnected components. Nodes of one component form the cut.

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


Spanning Tree Property 1 Any edge in a spanning tree induces a cut in the graph: remove the edge and the spanning tree breaks into 2 disconnected components. Nodes of one component form the cut.
Undirected Graph Subgraph

2 1 3 4 7 8 5

6 9 10 1

2 4 3 7 8 5

6 9 10
Spanning Tree

Remove edge {3,4} from spanning tree S = {1, 2, 3 ,8} edges across cut: {2,4}, {3,4}, {7,8}
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10 6 9

35

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


Spanning Tree Property 1 Any edge in a spanning tree induces a cut in the graph: remove the edge and the spanning tree breaks into 2 disconnected components. Nodes of one component form the cut.
Undirected Graph Subgraph

2 1 3 4 7 8 5

6 9 10 1

2 4 3 7 8 5

6 9 10
Spanning Tree

Remove edge {4,6} from spanning tree S = {1, 2, 3 , 4, 5, 1 7, 8} edges across cut: {4,6}, {5,10}, {7,10}
2 4 3 7 8 5 10 6 9 1 3 2 4 7 8 5 10 6 9

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


Spanning Tree Property 1 Any edge in a spanning tree induces a cut in the graph: remove the edge and the spanning tree breaks into 2 disconnected components. Nodes of one component form the cut.
Undirected Graph Subgraph

2 1 3 4 7 8 5

6 9 10 1

2 4 3 7 8 5

6 9 10
Spanning Tree

Remove edge {4,6} from spanning tree S = {1, 2, 3 , 4, 5, 1 7, 8} edges across cut: {4,6}, {5,10}, {7,10}
2 4 3 7 8 5 10 6 9 1 3 2 4 7 8 5 10 6 9

Q. Why does removing an edge break a spanning tree into exactly two components? A. What does it mean if removing edge did not result in a disconnected graph? What does it mean if removing edge results in more than 2 disconnected components?

36

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


Spanning Tree Property 2 If edge {i,j} is part of a spanning tree T that induces a cut S, and edge {k,l} is an edge across the cut, then removing {i,j} from T and replacing it with {k,l} will result in another spanning tree.

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


Spanning Tree Property 2 If edge {i,j} is part of a spanning tree T that induces a cut S, and edge {k,l} is an edge across the cut, then removing {i,j} from T and replacing it with {k,l} will result in another spanning tree.
Undirected Graph Subgraph

2 1 3 4 7 8 5

6 9 10 1

2 4 3 7 8 5

6 9 10
Spanning Tree

Remove edge {3,4} and replace with {7,8} S = {1, 2, 3 ,8} edges across cut: {2,4}, {3,4}, {7,8}
2 1 3 4 7 8 5 10 6 9 1 3 2 4 7 8 5 10 6 9

37

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


Spanning Tree Property 2 If edge {i,j} is part of a spanning tree T that induces a cut S, and edge {k,l} is an edge across the cut, then removing {i,j} from T and replacing it with {k,l} will result in another spanning tree.
Undirected Graph Subgraph

2 1 3 4 7 8 5

6 9 10 1

2 4 3 7 8 5

6 9 10
Spanning Tree

Remove edge {4,6} and replace with {7,10} S = {1, 2, 3 , 4, 5, 1 7, 8} edges across cut: {4,6}, {5,10}, {7,10}
2 4 3 7 8 5 10 6 9 1 3 2 4 7 8 5 10 6 9

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


Spanning Tree Property 2 If edge {i,j} is part of a spanning tree T that induces a cut S, and edge {k,l} is an edge across the cut, then removing {i,j} from T and replacing it with {k,l} will result in another spanning tree.
Undirected Graph Subgraph

2 1 3 4 7 8 5

6 9 10 1

2 4 3 7 8 5

6 9 10
Spanning Tree

Remove edge {4,6} and replace with {7,10} S = {1, 2, 3 , 4, 5, 1 7, 8} edges across cut: {4,6}, {5,10}, {7,10}
2 4 3 7 8 5 10 6 9 1 3 2 4 7 8 5 10 6 9

Q. Why does replacing edges across a cut lead to another spanning tree? A. We start with n nodes and n-1 edge, then remove an edge and replace with another edge. Since both edges cross the same cut, the graph will be connected.

38

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


We will now use Property 2 to derive an optimality condition for MST: Cut optimality condition for MST A spanning tree T is an MST if and only if for every edge {i,j} in T, cij < ckl for all edges {k,l} contained in the cut formed by removing {i,j} from T.

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


We will now use Property 2 to derive an optimality condition for MST: Cut optimality condition for MST A spanning tree T is an MST if and only if for every edge {i,j} in T, cij < ckl for all edges {k,l} contained in the cut formed by removing {i,j} from T.

Undirected Graph

Subgraph

2 1 3 4 7 8 5

6 9 10 1

2 4 3 7 8 5

6 9 10

Spanning Tree T

For T to be an MST, we must have: c1,2 < c2,3, c1,2 < c2,4

39

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


We will now use Property 2 to derive an optimality condition for MST: Cut optimality condition for MST A spanning tree T is an MST if and only if for every edge {i,j} in T, cij < ckl for all edges {k,l} contained in the cut formed by removing {i,j} from T.

Undirected Graph

Subgraph

2 1 3 4 7 8 5

6 9 10 1

2 4 3 7 8 5

6 9 10

Spanning Tree T

For T to be an MST, we must have: c1,2 < c2,3, c1,2 < c2,4 c1,3 < c2,3, c1,3 < c2,4

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


We will now use Property 2 to derive an optimality condition for MST: Cut optimality condition for MST A spanning tree T is an MST if and only if for every edge {i,j} in T, cij < ckl for all edges {k,l} contained in the cut formed by removing {i,j} from T.

Undirected Graph

Subgraph

2 1 3 4 7 8 5

6 9 10 1

2 4 3 7 8 5

6 9 10

Spanning Tree T

For T to be an MST, we must have: c1,2 < c2,3, c1,2 < c2,4 c1,3 < c2,3, c1,3 < c2,4 c3,4 < c2,4, c3,4 < c8,7

40

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


We will now use Property 2 to derive an optimality condition for MST: Cut optimality condition for MST A spanning tree T is an MST if and only if for every edge {i,j} in T, cij < ckl for all edges {k,l} contained in the cut formed by removing {i,j} from T.

Undirected Graph

Subgraph

2 1 3 4 7 8 5

6 9 10 1

2 4 3 7 8 5

6 9 10

Spanning Tree T

For T to be an MST, we must have: c1,2 < c2,3, c1,2 < c2,4 c1,3 < c2,3, c1,3 < c2,4 c3,4 < c2,4, c3,4 < c8,7 c4,6 < c5,10, c4,6 < c7,10 :

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


We will now use Property 2 to derive an optimality condition for MST: Cut optimality condition for MST A spanning tree T is an MST if and only if for every edge {i,j} in T, cij < ckl for all edges {k,l} contained in the cut formed by removing {i,j} from T.

Proof: First, show that if T does not satisfy the cut optimality condition, then T cannot be an MST:
From property 2 we know that we can replace an edge {i,j} belonging to T with another edge {k,l} across the cut induced by {i,j} and obtain another spanning tree. Hence, if cij > ckl, then the new tree obtained by replacing {i,j} with {k,l} will have lower cost T cannot be an MST.

Second, show that if T satisfies the cut optimality condition, then T must be an MST:
Suppose T satisfies the cut optimality condition and let T* be an MST. We show that T and T* must have the same cost and thus, T must also be optimal. Let {i,j} be an edge in T but not in T*. Consider the cut induced by {i,j}. Since T* is connected, there must be an edge {k,l} in T* that crosses this cut. Since T satisfies the optimality condition we must have cij < ckl. If cij < ckl, then we could improve T* and therefore cij = ckl. We can repeat this until T is the same as T*. Note that each time we replace an edge in T with an edge in T* with the same cost and hence T and T* must have the same cost.

41

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


We will now use Property 2 to derive an optimality condition for MST: Cut optimality condition for MST A spanning tree T is an MST if and only if for every edge {i,j} in T, cij < ckl for all edges {k,l} contained in the cut formed by removing {i,j} from T.

Proof: First, show that if T does not satisfy the cut optimality condition, then T cannot be an MST:
From property 2 we know that we can replace an edge {i,j} belonging to T with another edge {k,l} across the cut induced by {i,j} and obtain another spanning tree. Hence, if cij > ckl, then the new tree obtained by replacing {i,j} with {k,l} will have lower cost T cannot be an MST.

Second, show that if T satisfies the cut optimality condition, then T must be an MST:
Suppose T satisfies the cut optimality condition and let T* be an MST. We show that T and T* must have the same cost and thus, T must also be optimal. Let {i,j} be an edge in T but not in T*. Consider the cut induced by {i,j}. Since T* is connected, there must be an edge {k,l} in T* that crosses this cut. Since T satisfies the optimality condition we must have cij < ckl. If cij < ckl, then we could improve T* and therefore cij = ckl. We can repeat this until T is the same as T*. Note that each time we replace an edge in T with an edge in T* with the same cost and hence T and T* must have the same cost.

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


We will now use Property 2 to derive an optimality condition for MST: Cut optimality condition for MST A spanning tree T is an MST if and only if for every edge {i,j} in T, cij < ckl for all edges {k,l} contained in the cut formed by removing {i,j} from T.

Proof: First, show that if T does not satisfy the cut optimality condition, then T cannot be an MST:
From property 2 we know that we can replace an edge {i,j} belonging to T with another edge {k,l} across the cut induced by {i,j} and obtain another spanning tree. Hence, if cij > ckl, then the new tree obtained by replacing {i,j} with {k,l} will have lower cost T cannot be an MST.

Second, show that if T satisfies the cut optimality condition, then T must be an MST:
Suppose T satisfies the cut optimality condition and let T* be an MST. We show that T and T* must have the same cost and thus, T must also be optimal. Let {i,j} be an edge in T but not in T*. Consider the cut induced by {i,j}. Since T* is connected, there must be an edge {k,l} in T* that crosses this cut. Since T satisfies the optimality condition we must have cij < ckl. If cij < ckl, then we could improve T* and therefore cij = ckl. We can repeat this until T is the same as T*. Note that each time we replace an edge in T with an edge in T* with the same cost and hence T and T* must have the same cost.

42

Lec 7

Network Models: Properties of (Minimum) Spanning Trees


We will now use Property 2 to derive an optimality condition for MST: Cut optimality condition for MST A spanning tree T is an MST if and only if for every edge {i,j} in T, cij < ckl for all edges {k,l} contained in the cut formed by removing {i,j} from T.

Proof: First, show that if T does not satisfy the cut optimality condition, then T cannot be an MST:
From property 2 we know that we can replace an edge {i,j} belonging to T with another edge {k,l} across the cut induced by {i,j} and obtain another spanning tree. Hence, if cij > ckl, then the new tree obtained by replacing {i,j} with {k,l} will have lower cost T cannot be an MST.

Second, show that if T satisfies the cut optimality condition, then T must be an MST:
Suppose T satisfies the cut optimality condition and let T* be an MST. We show that T and T* must have the same cost and thus, T must also be optimal. Let {i,j} be an edge in T but not in T*. Consider the cut induced by {i,j}. Since T* is connected, there must be an edge {k,l} in T* that crosses this cut. Since T satisfies the optimality condition we must have cij < ckl. If cij < ckl, then we could improve T* and therefore cij = ckl. We can repeat this until T is the same as T*. Note that each time we replace an edge in T with an edge in T* with the same cost and hence T and T* must have the same cost.

Lec 7

Network Models: Algorithms for MST


Prims Algorithm for MST (1957) 1. 2. 3. Select any node in the graph Connect this node to the nearest (lowest cost) node Considering all nodes that are now connected, find and connect the nearest node that is not connected. Break ties arbitrarily. Repeat third step until all nodes are connected

4.

Q. Will Prims algorithm always construct a minimum spanning tree? A. Yes. If Prims algorithm did not construct an MST, then from the cut optimality condition of MST, there would be an edge {i,j} in the spanning tree constructed by the algorithm that can be replaced by another edge {k,l} that crosses the cut induced by {i,j} and with lower cost (i.e. ckl < cij). Hence, swapping {i,j} with {k,l} would lead to a better spanning tree. However, if ckl < cij then step 3 of the algorithm would have chosen {k,l} as the nearest connection between connected and unconnected nodes and not {i,j}. Hence, Prims algorithm must construct an MST.

43

Lec 7

Network Models: Algorithms for MST


Prims Algorithm for MST (1957) 1. 2. 3. Select any node in the graph Connect this node to the nearest (lowest cost) node Considering all nodes that are now connected, find and connect the nearest node that is not connected. Break ties arbitrarily. Repeat third step until all nodes are connected

4.

Q. Will Prims algorithm always construct a minimum spanning tree?

Q. Is it possible for {i,j} to be chosen instead of {k,l} if cij > ckl?

Connected nodes

Unconnected nodes

Lec 7

Network Models: Algorithms for MST


Prims Algorithm for MST (1957) 1. 2. 3. Select any node in the graph Connect this node to the nearest (lowest cost) node Considering all nodes that are now connected, find and connect the nearest node that is not connected. Break ties arbitrarily. Repeat third step until all nodes are connected

4.

Q. Will Prims algorithm always construct a minimum spanning tree? A. Yes. If Prims algorithm did not construct an MST, then from the cut optimality condition of MST, there would be an edge {i,j} in the spanning tree constructed by the algorithm that can be replaced by another edge {k,l} that crosses the cut induced by {i,j} and with lower cost (i.e. ckl < cij). Hence, swapping {i,j} with {k,l} would lead to a better spanning tree. However, if ckl < cij then step 3 of the algorithm would have chosen {k,l} as the nearest connection between connected and unconnected nodes and not {i,j}. Hence, Prims algorithm must construct an MST.

44

You might also like