Minimum Spanning Trees

Similar documents
Minimum Spanning Trees

COMP108 Algorithmic Foundations

Preview. Graph. Graph. Graph. Graph Representation. Graph Representation 12/3/2018. Graph Graph Representation Graph Search Algorithms

Spanning Tree. Preview. Minimum Spanning Tree. Minimum Spanning Tree. Minimum Spanning Tree. Minimum Spanning Tree 10/17/2017.

An undirected graph G = (V, E) V a set of vertices E a set of unordered edges (v,w) where v, w in V

FSA. CmSc 365 Theory of Computation. Finite State Automata and Regular Expressions (Chapter 2, Section 2.3) ALPHABET operations: U, concatenation, *

Outline. Circuits. Euler paths/circuits 4/25/12. Part 10. Graphs. Euler s bridge problem (Bridges of Konigsberg Problem)

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

CS 461, Lecture 17. Today s Outline. Example Run

CSC Design and Analysis of Algorithms. Example: Change-Making Problem

Weighted Matching and Linear Programming

Outline. 1 Introduction. 2 Min-Cost Spanning Trees. 4 Example

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

Ch 1.2: Solutions of Some Differential Equations

Searching Linked Lists. Perfect Skip List. Building a Skip List. Skip List Analysis (1) Assume the list is sorted, but is stored in a linked list.

Outline. Computer Science 331. Computation of Min-Cost Spanning Trees. Costs of Spanning Trees in Weighted Graphs

Week 3: Connected Subgraphs

Integration Continued. Integration by Parts Solving Definite Integrals: Area Under a Curve Improper Integrals

Weighted graphs -- reminder. Data Structures LECTURE 15. Shortest paths algorithms. Example: weighted graph. Two basic properties of shortest paths

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

Strongly Connected Components

Cycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!

Basic Polyhedral theory

V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

b. How many ternary words of length 23 with eight 0 s, nine 1 s and six 2 s?

TOPIC 5: INTEGRATION

INTEGRALS. Chapter 7. d dx. 7.1 Overview Let d dx F (x) = f (x). Then, we write f ( x)

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

Walk Like a Mathematician Learning Task:

CS200: Graphs. Graphs. Directed Graphs. Graphs/Networks Around Us. What can this represent? Sometimes we want to represent directionality:

The Equitable Dominating Graph

CSI35 Chapter 11 Review

Lecture 20: Minimum Spanning Trees (CLRS 23)

CSE303 - Introduction to the Theory of Computing Sample Solutions for Exercises on Finite Automata

Graph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2

On spanning trees and cycles of multicolored point sets with few intersections

Lecture 11 Waves in Periodic Potentials Today: Questions you should be able to address after today s lecture:

4.5 Minimum Spanning Tree. Chapter 4. Greedy Algorithms. Minimum Spanning Tree. Applications

13. Binary tree, height 4, eight terminal vertices 14. Full binary tree, seven vertices v 7 v13. v 19

Examples and applications on SSSP and MST

1 Minimum Cut Problem

cycle that does not cross any edges (including its own), then it has at least

CSE 373. Graphs 1: Concepts, Depth/Breadth-First Search reading: Weiss Ch. 9. slides created by Marty Stepp

Constructive Geometric Constraint Solving

Section 3: Antiderivatives of Formulas

Graphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari

Graphs. Graphs. Graphs: Basic Terminology. Directed Graphs. Dr Papalaskari 1

4.5 Minimum Spanning Tree. Chapter 4. Greedy Algorithms. Minimum Spanning Tree. Motivating application

CSE 373: AVL trees. Warmup: Warmup. Interlude: Exploring the balance invariant. AVL Trees: Invariants. AVL tree invariants review

a b c cat CAT A B C Aa Bb Cc cat cat Lesson 1 (Part 1) Verbal lesson: Capital Letters Make The Same Sound Lesson 1 (Part 1) continued...

1.2. Linear Variable Coefficient Equations. y + b "! = a y + b " Remark: The case b = 0 and a non-constant can be solved with the same idea as above.

Exam 1 Solution. CS 542 Advanced Data Structures and Algorithms 2/14/2013

Why the Junction Tree Algorithm? The Junction Tree Algorithm. Clique Potential Representation. Overview. Chris Williams 1.

Linear Algebra Existence of the determinant. Expansion according to a row.

Riemann Sums and Riemann Integrals

CONTINUITY AND DIFFERENTIABILITY

Last time: introduced our first computational model the DFA.

Riemann Sums and Riemann Integrals

, between the vertical lines x a and x b. Given a demand curve, having price as a function of quantity, p f (x) at height k is the curve f ( x,

Connected-components. Summary of lecture 9. Algorithms and Data Structures Disjoint sets. Example: connected components in graphs

1 Introduction to Modulo 7 Arithmetic

Chapter 16. 1) is a particular point on the graph of the function. 1. y, where x y 1

Algorithmic and NP-Completeness Aspects of a Total Lict Domination Number of a Graph

CS 241 Analysis of Algorithms

Instructions for Section 1

Abstract Interpretation: concrete and abstract semantics

CS 253: Algorithms. Chapter 24. Shortest Paths. Credit: Dr. George Bebis

Analysis of Algorithms - Elementary graphs algorithms -

10. EXTENDING TRACTABILITY

DFA (Deterministic Finite Automata) q a

priority queue ADT heaps 1

(a) v 1. v a. v i. v s. (b)

, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management

Problem solving by search

Analysis of Algorithms - Elementary graphs algorithms -

ME 522 PRINCIPLES OF ROBOTICS. FIRST MIDTERM EXAMINATION April 19, M. Kemal Özgören

CIVL 8/ D Boundary Value Problems - Rectangular Elements 1/7

Linked-List Implementation. Linked-lists for two sets. Multiple Operations. UNION Implementation. An Application of Disjoint-Set 1/9/2014

This Week. Computer Graphics. Introduction. Introduction. Graphics Maths by Example. Graphics Maths by Example

Lecture 3 ( ) (translated and slightly adapted from lecture notes by Martin Klazar)

5/7/13. Part 10. Graphs. Theorem Theorem Graphs Describing Precedence. Outline. Theorem 10-1: The Handshaking Theorem

CS 103 BFS Alorithm. Mark Redekopp

CS61B Lecture #33. Administrivia: Autograder will run this evening. Today s Readings: Graph Structures: DSIJ, Chapter 12

Outlines: Graphs Part-4. Applications of Depth-First Search. Directed Acyclic Graph (DAG) Generic scheduling problem.

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

1 The Riemann Integral

We partition C into n small arcs by forming a partition of [a, b] by picking s i as follows: a = s 0 < s 1 < < s n = b.

Engineering 323 Beautiful HW #13 Page 1 of 6 Brown Problem 5-12

Module graph.py. 1 Introduction. 2 Graph basics. 3 Module graph.py. 3.1 Objects. CS 231 Naomi Nishimura

Case Study VI Answers PHA 5127 Fall 2006

CPSC 665 : An Algorithmist s Toolkit Lecture 4 : 21 Jan Linear Programming

Propositional Logic. Combinatorial Problem Solving (CPS) Albert Oliveras Enric Rodríguez-Carbonell. May 17, 2018

Announcements. These are Graphs. This is not a Graph. Graph Definitions. Applications of Graphs. Graphs & Graph Algorithms

Combinatorial Networks Week 1, March 11-12

A general N-dimensional vector consists of N values. They can be arranged as a column or a row and can be real or complex.

Winter 2016 COMP-250: Introduction to Computer Science. Lecture 23, April 5, 2016

Convert the NFA into DFA

Greedy Algorithms, Activity Selection, Minimum Spanning Trees Scribes: Logan Short (2015), Virginia Date: May 18, 2016

Transcription:

Minimum Spnning Trs

Minimum Spnning Trs Problm A town hs st of houss nd st of rods A rod conncts nd only houss A rod conncting houss u nd v hs rpir cost w(u, v) Gol: Rpir nough (nd no mor) rods such tht: 1. Evryon stys connctd: cn rch vry hous from ll othr houss, nd. Totl rpir cost is minimum 11 b c d i 6 1 h g f 1

Minimum Spnning Trs A connctd, undirctd grph: Vrtics = houss, Edgs = rods A wight w(u, v) on ch dg (u, v) E Find T E such tht: 1. T conncts ll vrtics. w(t) = Σ (u,v) T w(u, v) is minimizd b c d 11 i 1 h 1 g f 3

Minimum Spnning Trs T forms tr = spnning tr A spnning tr whos wight is minimum ovr ll spnning trs is clld minimum spnning tr, or MST. b c d 11 i 1 g 1 g f

Proprtis of Minimum Spnning Trs Minimum spnning trs r not uniqu Cn rplc (b, c) with (, h) to obtin diffrnt spnning tr with th sm cost MST hv no cycls W cn tk out n dg of cycl, nd still hv th vrtics connctd whil rducing th cost b c d 11 i 1 h 1 g f # of dgs in MST: V - 1 5

Growing MST Minimum-spnning-tr problm: find MST for connctd, undirctd grph, with wight function ssocitd with its dgs A gnric solution: Build st A of dgs (initilly mpty) Incrmntlly dd dgs to A such tht thy would blong to MST An dg (u, v) is sf for A if nd only if A {(u, v)} is lso subst of som MST 11 b c d i 6 1 h g f 1 W will dd only sf dgs 6

Gnric MST lgorithm 1. A. whil A is not spnning tr 3. do find n dg (u, v) tht is sf for A. A A {(u, v)} 5. rturn A How do w find sf dgs? b c d 11 i 1 h 1 g f

Finding Sf Edgs Lt s look t dg (h, g) Is it sf for A initilly? Ltr on: S b c d 11 i 1 h 1 g f V - S Lt S V b ny st of vrtics tht includs h but not g (so tht g is in V - S) In ny MST, thr hs to b on dg (t lst) tht conncts S with V - S Why not choos th dg with minimum wight (h,g)?

Dfinitions A cut (S, V - S) is prtition of vrtics into disjoint sts S nd V - S An dg crosss th cut b c d S 11 i 1 S V- S V- S h g f 1 (S, V - S) if on ndpoint is in S nd th othr in V S A cut rspcts st A of dgs no dg in A crosss th cut An dg is light dg crossing cut its wight is minimum ovr ll dgs crossing th cut For givn cut, thr cn b > 1 light dg crossing it

Thorm Lt A b subst of som MST, (S, V - S) b cut tht rspcts A, nd (u, v) b light dg crossing (S, V - S). Thn (u, v) is sf for A. Proof: Lt T b MST tht includs A Edgs in A r shdd Assum T dos not includ th dg (u, v) Id: construct nothr MST T tht includs A {(u, v)} u v S V - S

Thorm - Proof T contins uniqu pth p btwn u nd v (u, v) forms cycl with dgs on p S (u, v) crosss th cut pth p x must cross th cut (S, V - S) t lst onc: lt (x, y) b tht dg Lt s rmov (x, y) brks T into two componnts. u v p V - S y Adding (u, v) rconncts th componnts T = T - {(x, y)} {(u, v)} 11

Thorm Proof (cont.) T = T - {(x, y)} {(u, v)} Hv to show tht T is MST: S (u, v) is light dg w(u, v) w(x, y) w(t ) = w(t) - w(x, y) + w(u, v) w(t) Sinc T is spnning tr u v p x V - S y w(t) w(t ) T must b n MST s wll 1

Thorm Proof (cont.) Nd to show tht (u, v) is sf for A: i.., (u, v) cn b prt of MST A T nd (x, y) A A T S x A {(u, v)} T Sinc T is n MST u p y (u, v) is sf for A v V - S 13

Discussion In GENERIC-MST: A is forst contining connctd componnts Initilly, ch componnt is singl vrtx Any sf dg mrgs two of ths componnts into on Ech componnt is tr Sinc n MST hs xctly V - 1 dgs - ftr itrting V - 1 tims, w hv only on componnt 1

Th Algorithm of Kruskl Strt with ch vrtx bing its own componnt Rptdly mrg two componnts into on by choosing th light dg tht conncts thm 11 b c d i 6 1 h g f 1 W would dd dg (c, f) Scn th st of dgs in monotoniclly incrsing ordr by wight Uss disjoint-st dt structur to dtrmin whthr n dg conncts vrtics in diffrnt componnts 15

Oprtions on Disjoint Dt Sts MAKE-SET(u) crts nw st whos only mmbr is u FIND-SET(u) rturns rprsnttiv lmnt from th st tht contins u My b ny of th lmnts of th st tht hs prticulr proprty E.g.: S u = {r, s, t, u}, th proprty is tht th lmnt b th first on lphbticlly FIND-SET(u) = r FIND-SET(s) = r FIND-SET hs to rturn th sm vlu for givn st 16

Oprtions on Disjoint Dt Sts UNION(u, v) units th dynmic sts tht contin u nd v, sy S u nd S v E.g.: S u = {r, s, t, u}, S v = {v, x, y} UNION (u, v) = {r, s, t, u, v, x, y} 1

KRUSKAL(V, E, w) 1. A. for ch vrtx v V 3. do MAKE-SET(v). sort E into non-dcrsing ordr by wight w 5. for ch (u, v) tkn from th sortd list 6. do if FIND-SET(u) FIND-SET(v). thn A A {(u, v)}. UNION(u, v). rturn A Running tim: O(E lgv) dpndnt on th implmnttion of th disjoint-st dt structur 1

Exmpl 11 1: (h, g) b c d : (c, i), (g, f) : (, b), (c, f) 6: (i, g) : (c, d), (i, h) i 6 1 h g f 1 : (, h), (b, c) : (d, ) : (, f) 11: (b, h) 1: (d, f) {}, {b}, {c}, {d}, {}, {f}, {g}, {h}, {i} 1. Add (h, g). Add (c, i) 3. Add (g, f). Add (, b) 5. Add (c, f) 6. Ignor (i, g). Add (c, d). Ignor (i, h). Add (, h). Ignor (b, c) 11. Add (d, ) 1. Ignor (, f) 13. Ignor (b, h) 1. Ignor (d, f) {g, h}, {}, {b}, {c}, {d}, {}, {f}, {i} {g, h}, {c, i}, {}, {b}, {d}, {}, {f} {g, h, f}, {c, i}, {}, {b}, {d}, {} {g, h, f}, {c, i}, {, b}, {d}, {} {g, h, f, c, i}, {, b}, {d}, {} {g, h, f, c, i}, {, b}, {d}, {} {g, h, f, c, i, d}, {, b}, {} {g, h, f, c, i, d}, {, b}, {} {g, h, f, c, i, d,, b}, {} {g, h, f, c, i, d,, b}, {} {g, h, f, c, i, d,, b, } {g, h, f, c, i, d,, b, } {g, h, f, c, i, d,, b, } {g, h, f, c, i, d,, b, } 1

Th lgorithm of Prim Th dgs in st A lwys form singl tr Strts from n rbitrry root : V A = {} At ch stp: Find light dg crossing cut (V A, V - V A ) Add this dg to A Rpt until th tr spns ll vrtics Grdy strtgy b c d 11 i 1 h 1 g f At ch stp th dg ddd contributs th minimum mount possibl to th wight of th tr 0

How to Find Light Edgs Quickly? Us priority quu Q: Contins ll vrtics not yt includd in th tr (V V A ) V = {}, Q = {b, c, d,, f, g, h, i} With ch vrtx w ssocit ky: b c d 11 i 1 h g f 1 ky[v] = minimum wight of ny dg (u, v) conncting v to vrtx in th tr Ky of v is if v is not djcnt to ny vrtics in V A Aftr dding nw nod to V A w updt th wights of ll th nods djcnt to it W ddd nod ky[b] =, ky[h] = 1

PRIM(V, E, w, r) 1. Q b c d. for ch u V 0 3. do ky[u] 11 i 1. π[u] NIL 5. INSERT(Q, u) h g f 1 6. DECREASE-KEY(Q, r, 0) 0. whil Q Q = {, b, c, d,, f, g, h, i}. do u EXTRACT-MIN(Q) V A =. for ch v Adj[u] Extrct-MIN(Q). do if v Q nd w(u, v) < ky[v] 11. thn π[v] u 1. DECREASE-KEY(Q, v, w(u, v))

Exmpl b c d 11 i 1 h g f 1 0 Q = {, b, c, d,, f, g, h, i} V A = Extrct-MIN(Q) b c d 11 i 1 h g f 1 ky [b] = π [b] = ky [h] = π [h] = Q = {b, c, d,, f, g, h, i} V A = {} Extrct-MIN(Q) b 3

Exmpl b c d 11 i 1 h g f 1 b c d 11 i 1 h g f 1 ky [c] = π [c] = b ky [h] = π [h] = - unchngd Q = {c, d,, f, g, h, i} V A = {, b} Extrct-MIN(Q) c ky [d] = π [d] = c ky [f] = π [f] = c ky [i] = π [i] = c Q = {d,, f, g, h, i} V A = {, b, c} Extrct-MIN(Q) i

Exmpl b c d 11 i 1 h g f 1 b c d 11 i 1 h 1 g f ky [h] = π [h] = i ky [g] = 6 π [g] = i Q = {d,, f, g, h} V A = {, b, c, i} Extrct-MIN(Q) f ky [g] = π [g] = f ky [d] = π [d] = c unchngd ky [] = π [] = f Q = {d,, g, h} V A = {, b, c, i, f} Extrct-MIN(Q) g 5

Exmpl b c d 11 i 1 h 1 g f 1 b c d 11 i 1 h 1 g f 1 ky [h] = 1 π [h] = g 1 Q = {d,, h} V A = {, b, c, i, f, g} Extrct-MIN(Q) h Q = {d, } V A = {, b, c, i, f, g, h} Extrct-MIN(Q) d 6

Exmpl b c d 11 i 1 h 1 g f 1 ky [] = π [] = f Q = {} V A = {, b, c, i, f, g, h, d} Extrct-MIN(Q) Q = V A = {, b, c, i, f, g, h, d, }

PRIM(V, E, w, r) 1. Q. for ch u V 3. do ky[u]. π[u] NIL 5. INSERT(Q, u) 6. DECREASE-KEY(Q, r, 0) ky[r] 0. whil Q. do u EXTRACT-MIN(Q). for ch v Adj[u]. do if v Q nd w(u, v) < ky[v] 11. thn π[v] u Totl tim: O(VlgV + ElgV) = O(ElgV) O(V) if Q is implmntd s min-hp Excutd V tims Tks O(lgV) Excutd O(E) tims Constnt 1. DECREASE-KEY(Q, v, w(u, v)) Min-hp oprtions: O(VlgV) Tks O(lgV) O(ElgV)