MA/CSSE 473 Day 33 Student Questions Change to HW 13

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Chapter 23 Minimum Spanning Tree
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.
CSCE 411H Design and Analysis of Algorithms Set 8: Greedy Algorithms Prof. Evdokia Nikolova* Spring 2013 CSCE 411H, Spring 2013: Set 8 1 * Slides adapted.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 13 Minumum spanning trees Motivation Properties of minimum spanning trees Kruskal’s.
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.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
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.
Lecture 27 CSE 331 Nov 6, Homework related stuff Solutions to HW 7 and HW 8 at the END of the lecture Turn in HW 7.
1 Minimum Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting.
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.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
MA/CSSE 473 Day 36 Kruskal proof recap Prim Data Structures and detailed algorithm.
ADA: 10. MSTs1 Objective o look at two algorithms for finding mimimum spanning trees (MSTs) over graphs Prim's algorithm, Kruskal's algorithm Algorithm.
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.
MA/CSSE 473 Days Answers to student questions Prim's Algorithm details and data structures Kruskal details.
1 Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that are: b feasible b locally optimal.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Minimum- Spanning Trees
MA/CSSE 473 Day 34 MST details: Kruskal's Algorithm Prim's Algorithm.
Design and Analysis of Algorithms - Chapter 91 Greedy algorithms Optimization problems solved through a sequence of choices that are: b feasible b locally.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
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),
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Minimum Spanning Tree Graph Theory Basics - Anil Kishore.
Lecture ? The Algorithms of Kruskal and Prim
Minimum Spanning Trees
Introduction to Algorithms
MA/CSSE 473 Day 36 Student Questions More on Minimal Spanning Trees
Minimum Spanning Trees
Minimum Spanning Trees
Minimum Spanning Trees
MA/CSSE 473 Days Answers to student questions
Spanning Trees Kruskel’s Algorithm Prim’s Algorithm
Minimum Spanning Trees
Lecture 12 Algorithm Analysis
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
MA/CSSE 473 Day 36 Kruskal proof recap
Minimum-Cost Spanning Tree
CSCE350 Algorithms and Data Structure
Minimum Spanning Tree.
Minimum Spanning Tree.
Minimum Spanning Tree.
Minimum Spanning Trees
Spanning Trees.
Minimum-Cost Spanning Tree
Data Structures – LECTURE 13 Minumum spanning trees
Chapter 23 Minimum Spanning Tree
Outline This topic covers Prim’s algorithm:
Minimum-Cost Spanning Tree
Minimum Spanning Trees
Minimum Spanning Tree Section 7.3: Examples {1,2,3,4}
Chapter 11 Graphs.
Lecture 12 Algorithm Analysis
Minimum Spanning Tree Algorithms
Minimum Spanning Trees
Minimum Spanning Tree.
CSE 373: Data Structures and Algorithms
Lecture 12 Algorithm Analysis
Lecture 14 Minimum Spanning Tree (cont’d)
Chapter 23: Minimum Spanning Trees: A graph optimization problem
Minimum-Cost Spanning Tree
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Minimum Spanning Trees
Presentation transcript:

MA/CSSE 473 Day 33 Student Questions Change to HW 13 Minimal Spanning Tree Kruskal Prim

Algorithms for finding a Minimal Spanning tree Kruskal and Prim Algorithms for finding a Minimal Spanning tree

Kruskal’s algorithm To find a MST (minimal Spanning Tree): Start with a graph T containing all n of G’s vertices and none of its edges. for i = 1 to n – 1: Among all of G’s edges that can be added without creating a cycle, add to T an edge that has minimal weight. Details of Data Structures later

Prim’s algorithm Start with T as a single vertex of G (which is a MST for a single-node graph). for i = 1 to n – 1: Among all edges of G that connect a vertex in T to a vertex that is not yet in T, add a minimum-weight edge (and the vertex at the other end of T). Details of Data Structures later

Example of Prim’s algorithm

Correct? These algorithms seem simple enough, but do they really produce a MST? We examine lemma that is the crux of both proofs. It is subtle, but once we have it, the proofs are fairly simple.

MST lemma Let G be a weighted connected graph, let T be any MST of G, let G′ be any nonempty subgraph of T, and let C be any connected component of G′. Then: If we add to C an edge e=(v,w) that has minimum-weight among all edges that have one vertex in C and the other vertex not in C, G has an MST that contains the union of G′ and e. [WLOG, v is the vertex of e that is in C, and w is not in C] Summary: If G' is a subgraph of an MST, so is G'{e} Consider doing this one on the board, and showing the slides later. If so, do not include the next two slides in the on-line PDF until after class. Write on board: Graph G has MST T G' is a subgraph of T C is a connected component of G' e = (v,w) = minimal-weight-edge from C to G-C. Then do the steps

Does this algorithm actually produce an MST for G? Recap: MST lemma Let G be a weighted connected graph with an MST T; let G′ be any subgraph of T, and let C be any connected component of G′. If we add to C an edge e=(v,w) that has minimum-weight among all edges that have one vertex in C and the other vertex not in C, then G has an MST that contains the union of G′ and e. Recall Kruskal’s algorithm To find a MST for G: Start with a connected weighted graph containing all of G’s n vertices and none of its edges. for i = 1 to n – 1: Among all of G’s edges that can be added without creating a cycle, add one that has minimal weight. Does this algorithm actually produce an MST for G?

Does Kruskal produce a MST? Claim: After every step of Kruskal’s algorithm, we have a set of edges that is part of an MST of G Proof of claim: Base case … Induction step: Induction Assumption: before adding an edge we have a subgraph of an MST We must show that after adding the next edge we have a subgraph of an MST Details: Suppose that the most recently added edge is e = (v, w). Let C be the component (of the “before adding e” MST subgraph) that contains v Note that there must be such a component and that it is unique. Exists and is unique: Every vertex is part of some component (Every vertex starts out as its own component. Are all of the conditions of MST lemma met? Thus the new graph is a subgraph of some MST of G Once we have the claim, it is easy to see that once you get N-1 edges, you have a MST.

Does Prim produce an MST? Proof similar to Kruskal (but slightly simpler) It's done in the textbook

Recap: Prim’s Algorithm for Minimal Spanning Tree Start with T as a single vertex of G (which is a MST for a single-node graph). for i = 1 to n – 1: Among all edges of G that connect a vertex in T to a vertex that is not yet in T, add to T a minimum-weight edge. At each stage, T is a MST for a connected subgraph of G We now examine Prim more closely

Main Data Structures for Prim Start with adjacency-list representation of G Let V be all of the vertices of G, and let VT the subset consisting of the vertices that we have placed in the tree so far We need a way to keep track of "fringe" edges i.e. edges that have one vertex in VT and the other vertex in V – VT Fringe edges need to be ordered by edge weight E.g., in a priority queue What is the most efficient way to implement a priority queue? Ask about what is needed before revealing any parts of this slide A binary heap

Prim detailed algorithm summary Create a minheap from the adjacency-list representation of G Each heap entry contains a vertex and its weight The vertices in the heap are those not yet in T Weight associated with each vertex v is the minimum weight of an edge that connects v to some vertex in T If there is no such edge, v's weight is infinite Initially all vertices except start are in heap, have infinite weight Vertices in the heap whose weights are not infinite are the fringe vertices Fringe vertices are candidates to be the next vertex (with its associated edge) added to the tree Loop: Delete min weight vertex from heap, add it to T We may then be able to decrease the weights associated with one or vertices that are adjacent to v Ask about what is needed before revealing any parts of this slide A binary heap

MinHeap overview We need an operation that a standard binary heap doesn't support: decrease(vertex, newWeight) Decreases the value associated with a heap element Instead of putting vertices and associated edge weights directly in the heap: Put them in an array called key[] Put references to them in the heap

Min Heap methods init(key) build a MinHeap from the array of keys Ѳ(n) operation description run time init(key) build a MinHeap from the array of keys Ѳ(n) del() delete and return (the location in key[ ] of ) the minimum element Ѳ(log n) isIn(w) is vertex w currently in the heap? Ѳ(1) keyVal(w) The weight associated with vertex w (minimum weight of an edge from that vertex to some adjacent vertex that is in the tree). decrease(w, newWeight) changes the weight associated with vertex w to newWeight (which must be smaller than w's current weight)