Lecture 14 Minimum Spanning Tree (cont’d)

Slides:



Advertisements
Similar presentations
Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
Advertisements

1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
CSE 780 Algorithms Advanced Algorithms Minimum spanning tree Generic algorithm Kruskal’s algorithm Prim’s algorithm.
Minimum-Cost Spanning Tree weighted connected undirected graph spanning tree cost of spanning tree is sum of edge costs find spanning tree that has minimum.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Lecture 12 Minimum Spanning Tree. Motivating Example: Point to Multipoint Communication Single source, Multiple Destinations Broadcast – All nodes in.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 11 Instructor: Paul Beame.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
Minimum Spanning Trees What is a MST (Minimum Spanning Tree) and how to find it with Prim’s algorithm and Kruskal’s algorithm.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck.
2IL05 Data Structures Fall 2007 Lecture 13: Minimum Spanning Trees.
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Minimum spanning trees (MST) Def: A spanning tree of a graph G is an acyclic subset of edges of G connecting all vertices in G. A sub-forest of G is an.
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
Minimum- Spanning Trees
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
MST Lemma Let G = (V, E) be a connected, undirected graph with real-value weights on the edges. Let A be a viable subset of E (i.e. a subset of some MST),
Minimum Spanning Tree Graph Theory Basics - Anil Kishore.
Lecture ? The Algorithms of Kruskal and Prim
Minimum Spanning Trees
COMP108 Algorithmic Foundations Greedy methods
Introduction to Algorithms
Lecture 13 Shortest Path.
Minimum Spanning Trees
Lecture 26 CSE 331 Nov 2, 2016.
Lecture 22 Minimum Spanning Tree
Spanning Trees Kruskel’s Algorithm Prim’s Algorithm
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Three Graph Algorithms
Minimum-Cost Spanning Tree
CSCE350 Algorithms and Data Structure
Minimum Spanning Tree.
Minimum Spanning Trees
Minimum Spanning Tree.
Minimum-Cost Spanning Tree
Data Structures – LECTURE 13 Minumum spanning trees
Lecture 26 CSE 331 Nov 1, 2017.
Chapter 23 Minimum Spanning Tree
Minimum-Cost Spanning Tree
Autumn 2015 Lecture 10 Minimum Spanning Trees
MA/CSSE 473 Day 33 Student Questions Change to HW 13
Lecture 12 Algorithm Analysis
Minimum Spanning Tree Algorithms
Minimum Spanning Trees
Lecture 28 CSE 331 Nov 7, 2012.
Lecture 27 CSE 331 Nov 2, 2010.
Minimum Spanning Tree.
Minimum Spanning Trees
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
CSE 373: Data Structures and Algorithms
Autumn 2016 Lecture 10 Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Lecture 12 Shortest Path.
Winter 2019 Lecture 10 Minimum Spanning Trees
CSE 373: Data Structures and Algorithms
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Lecture 23: Minimum Spanning Trees
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Minimum-Cost Spanning Tree
Minimum Spanning Trees
Presentation transcript:

Lecture 14 Minimum Spanning Tree (cont’d)

Trees and cycles Adding any non-tree edge to a tree will introduce a cycle For a tree with a cycle, removing any edge in the cycle results in a tree. Basic operation: add an edge and remove another edge in the cycle created (swap).

General Algorithm for MST Initialize the tree to be empty. (initially a subset of some MST) Repeat Find a cut that does not have any edge in the current tree Add the min cost edge of the cut to the tree (by Key Lemma: still a subset of some MST) Until the tree has n-1 edges (Now we already have a tree, so it must be a MST)

Key Property Key Lemma: Suppose F is a set of edges that is inside some MST T, if 𝑆, 𝑆 is a cut that does not contain any edge in F and e is the minimum cost edge in the cut, then it is safe to add e to F. 𝐹∪ 𝑒 ⊂𝑇′ for some MST T’

Designing a MST algorithm Goal: do the two operations efficiently 1. How to find a cut that does not go through any edges we have chosen 2. How to find a minimum cost edge in the cut.

Prim’s algorithm Starting from an arbitrary vertex s. Make sure that the edges we select form a connected component including s. Choosing the cut: The set of vertices connected to s. Finding the minimum cost edge: Use a data-structure similar to Dijkstra.

Prim’s algorithm Prim(s) initialize dis[u] to be all infinity, prev[u] to be NULL For neighbors of s, initialize dis[u] = w[s,u], prev[u] = s Mark s as visited FOR i = 2 to n Among all vertices that are not visited, find the one with smallest distance, call it u. Mark u as visited FOR all edges (u,v) IF w[u,v] < dis[v] THEN dis[v] = w[u,v] prev[v] = u.

Dijkstra’s algorithm Dijkstra(s) initialize dis[u] to be all infinity, prev[u] to be NULL For neighbors of s, initialize dis[u] = w[s,u], prev[u] = s Mark s as visited FOR i = 2 to n Among all vertices that are not visited, find the one with smallest distance, call it u. Mark u as visited FOR all edges (u,v) IF dis[u]+w[u,v] < dis[v] THEN dis[v] = dis[u]+w[u,v] prev[v] = u.

Kruskal’s algorithm Idea: don’t try to find a cut, directly find the shortest edge. Algorithm: Sort the edges in ascending order of weight. For each edge, if adding it does not create a cycle, then add the edge to the tree. Checking the cycle needs a special data structure that we will talk about later.

Running time of Kruskal Sorting takes O(mlog m) time. For each edge, we need to check whether adding the edge creates a cycle. This can be done very efficiently (o(log m)). Total running time O(m log m)

Prim vs. Kruskal Running Time: Prim seems to be always faster O(m+nlog n) vs. O(m log m) However, the O(m+nlog n) version of Prim is not very easy to implement, and has a large hidden constant If you use a regular binary heap, the running time are the same, and Kruskal is usually faster in practice/easier to implement. If the graph is dense, O(n2) version of Prim is easy to implement and faster than Kruskal.