Presentation is loading. Please wait.

Presentation is loading. Please wait.

Minimum Spanning Tree Section 7.3: Examples {1,2,3,4}

Similar presentations


Presentation on theme: "Minimum Spanning Tree Section 7.3: Examples {1,2,3,4}"— Presentation transcript:

1 Minimum Spanning Tree Section 7.3: Examples {1,2,3,4}

2 Section 7.3: Examples

3

4

5

6

7 Paths and cycles A path is a sequence of nodes v1, v2, …, vN such that (vi,vi+1)E for 0<i<N The length of the path is N-1. Simple path: all vi are distinct, 0<i<N A cycle is a path such that v1=vN An acyclic graph has no cycles 7

8 Cycles BOS DTW SFO PIT JFK LAX 8

9 More useful definitions
In a directed graph: The indegree of a node v is the number of distinct edges (w,v)E. The outdegree of a node v is the number of distinct edges (v,w)E. A node with indegree 0 is a root. 9

10 Trees are graphs A dag is a directed acyclic graph.
A tree is a connected acyclic undirected graph. A forest is an acyclic undirected graph (not necessarily connected), i.e., each connected component is a tree. 10

11 Graph Traversals

12 Graph Traversals 12

13 Use of a stack It is very common to use a stack to keep track of:
nodes to be visited next, or nodes that we have already visited. Typically, use of a stack leads to a depth-first visit order. Depth-first visit order is “aggressive” in the sense that it examines complete paths. 13

14 Use of a queue It is very common to use a queue to keep track of:
nodes to be visited next, or nodes that we have already visited. Typically, use of a queue leads to a breadth-first visit order. Breadth-first visit order is “cautious” in the sense that it examines every path of length i before going on to paths of length i+1. 14

15 Minimum Spanning Trees
15

16 Problem: Laying Telephone Wire
Central office 16

17 Wiring: Naïve Approach
Central office Expensive! 17

18 Wiring: Better Approach
Central office Minimize the total length of wire connecting the customers 18

19 Understanding the terms
“Minimal cost” = Obvious “Spanning” = No isolated vertices “Tree” = A graph with no loops At step 3 draw the actual tree formed in example 1 6.5 Trees

20 Definition of MST Let G=(V,E) be a connected, undirected graph.
For each edge (u,v) in E, we have a weight w(u,v) specifying the cost (length of edge) to connect u and v. We wish to find a (acyclic) subset T of E that connects all of the vertices in V and whose total weight is minimized. Since the total weight is minimized, the subset T must be acyclic (no circuit). Thus, T is a tree. We call it a spanning tree. The problem of determining the tree T is called the minimum-spanning-tree problem.

21 Application of MST: an example
In the design of electronic circuitry, it is often necessary to make a set of pins electrically equivalent by wiring them together. Running cable TV to a set of houses. What’s the least amount of cable needed to still connect all the houses?

22 Where might this be useful? Can also be used to approximate some
Spanning Tree Definition A spanning tree of a graph G is a tree (acyclic) that connects all the vertices of G once i.e. the tree “spans” every vertex in G A Minimum Spanning Tree (MST) is a spanning tree on a weighted graph that has the minimum total weight Where might this be useful? Can also be used to approximate some NP-Complete problems

23 Here is an example of a connected graph and its minimum spanning tree:
b h c d e f g i 4 8 7 9 10 14 2 6 1 11 Notice that the tree is not unique: replacing (b,c) with (a,h) yields another spanning tree with the same minimum weight.

24 Minimum Spanning Trees
1/2/2019 6:45 AM Minimum Spanning Trees 2704 867 BOS 849 PVD ORD 187 740 144 1846 621 JFK 184 1258 802 SFO 1391 BWI 1464 337 1090 DFW 946 LAX 1235 1121 MIA 2342

25 Minimum Spanning Trees
Spanning subgraph Subgraph of a graph G containing all the vertices of G Spanning tree Spanning subgraph that is itself a (free) tree Minimum spanning tree (MST) Spanning tree of a weighted graph with minimum total edge weight Applications Communications networks Transportation networks ORD 10 1 PIT DEN 6 7 9 3 DCA STL 4 8 5 2 DFW ATL Minimum Spanning Trees

26 Minimum Spanning Trees
Cycle Property 8 4 2 3 6 7 9 e C f Cycle Property: Let T be a minimum spanning tree of a weighted graph G Let e be an edge of G that is not in T and C let be the cycle formed by e with T For every edge f of C, weight(f)  weight(e) Proof: By contradiction If weight(f) > weight(e) we can get a spanning tree of smaller weight by replacing e with f Replacing f with e yields a better spanning tree 8 4 2 3 6 7 9 C e f Minimum Spanning Trees

27 Minimum Spanning Trees
Partition Property U V 7 Partition Property: Consider a partition of the vertices of G into subsets U and V Let e be an edge of minimum weight across the partition There is a minimum spanning tree of G containing edge e Proof: Let T be an MST of G If T does not contain e, consider the cycle C formed by e with T and let f be an edge of C across the partition By the cycle property, weight(f)  weight(e) Thus, weight(f) = weight(e) We obtain another MST by replacing f with e f 4 9 5 2 8 8 3 e 7 Replacing f with e yields another MST U V 7 f 4 9 5 2 8 8 3 e 7 Minimum Spanning Trees

28 Minimum Spanning Trees
Example 7 7 D 7 D 2 2 B 4 B 4 8 9 5 9 5 5 2 F 2 F C C 8 8 3 3 8 8 E E A 7 A 7 7 7 7 7 7 D 2 7 D 2 B 4 B 4 5 9 5 5 9 4 2 F 5 C 2 F 8 C 8 3 8 3 8 E A E 7 7 A 7 7 Minimum Spanning Trees

29 Minimum Spanning Trees
Example (contd.) 7 7 D 2 B 4 9 4 5 5 2 F C 8 3 8 E A 3 7 7 7 D 2 B 4 5 9 4 5 2 F C 8 3 8 E A 3 7 Minimum Spanning Trees

30 Minimum Spanning Trees
Example JFK BOS MIA ORD LAX DFW SFO BWI PVD 867 2704 187 1258 849 740 144 1846 621 184 802 1391 1464 337 1090 946 1235 1121 2342 Minimum Spanning Trees

31 Prim's algorithm (simple)
MST_PRIM(G,w,r){ A={} S:={r} (r is an arbitrary node in V) Q=V-{r}; while Q is not empty do { take an edge (u, v) such that uS and vQ (vS ) and (u,v) is the shortest edge add (u, v) to A, add v to S and delete v from Q }

32 Prim's algorithm Initialization
for each vertex in graph set min_distance of vertex to ∞ set parent of vertex to null set minimum_adjacency_list of vertex to empty list set is_in_Q of vertex to true set min_distance of initial vertex to zero add to minimum-heap Q all vertices in graph, keyed by min_distance inputs: A graph, a function returning edge weights weight-function, and an initial vertex Initial placement of all vertices in the 'not yet seen' set, set initial vertex to be added to the tree, and place all vertices in a min-heap to allow for removal of the min distance from the minimum graph. Wikipedia

33 Prim's algorithm

34 Prim's algorithm

35 Prim's algorithm

36 Prim's algorithm

37 Prim's algorithm

38 Prim's algorithm

39 Prim's algorithm

40 Prim's algorithm

41 Prim's algorithm

42 Prim's algorithm

43 Prim's algorithm

44 Prim's algorithm

45 Prim's algorithm

46 Prim's algorithm

47 Prim's algorithm

48 Prim's algorithm

49 Prim's algorithm

50 Prim's algorithm

51 Another example

52 Prim’s algorithm d b c a  e b a d d b c a 4 5  e c Vertex Parent e -
9 b a 2 6 d d b c a 4 5 Vertex Parent e - b e c e d e 4 5 5 4 5 e c The MST initially consists of the vertex e, and we update the distances and parent for its adjacent vertices 52

53 Prim’s algorithm d b c a 4 5  b a d a c b 2 4 5 e c Vertex Parent e -
c e d e 9 b a 2 6 d 4 5 5 4 a c b 2 4 5 Vertex Parent e - b e c d d e a d 5 e c 53

54 Prim’s algorithm a c b 2 4 5 b a d e c b 4 5 c Vertex Parent e - b e
c d d e a d 9 b a 2 6 d 4 5 5 4 5 e c b 4 5 Vertex Parent e - b e c d d e a d c 54

55 Prim’s algorithm c b 4 5 b a d e b 5 c Vertex Parent e - b e c d d e
9 b a 2 6 d 4 5 5 4 5 e b 5 Vertex Parent e - b e c d d e a d c 55

56 Prim’s algorithm b 5 b a d e c The final minimum spanning tree
Vertex Parent e - b e c d d e a d 9 b a 2 6 d 4 5 5 4 5 e Vertex Parent e - b e c d d e a d c The final minimum spanning tree 56

57

58

59

60

61


Download ppt "Minimum Spanning Tree Section 7.3: Examples {1,2,3,4}"

Similar presentations


Ads by Google