COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.

Slides:



Advertisements
Similar presentations
Chapter 11 Trees Graphs III (Trees, MSTs) Reading: Epp Chp 11.5, 11.6.
Advertisements

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.
Graphs III (Trees, MSTs) (Chp 11.5, 11.6)
Graph Algorithms. Jaruloj Chongstitvatana Chapter 3: Greedy Algorithms 2 Outline Graph Representation Shortest path Minimum spanning trees.
Minimum Spanning Tree CSE 331 Section 2 James Daly.
3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
Tree tree = connected graph with no cycle tree = connected graph with |V|-1 edges tree = graph with |V|-1 edges and no cycles.
Lecture 18: Minimum Spanning Trees Shang-Hua Teng.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Is the following graph Hamiltonian- connected from vertex v? a). Yes b). No c). I have absolutely no idea v.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Minimum Spanning Trees
Chapter 9: Graphs Spanning Trees Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
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.
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.
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
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.
A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
Minimum Spanning Trees
Spring 2015 Lecture 11: Minimum Spanning Trees
© 2015 JW Ryder CSCI 203 Data Structures1. © 2015 JW Ryder CSCI 203 Data Structures2.
 2004 SDU Lecture 7- Minimum Spanning Tree-- Extension 1.Properties of Minimum Spanning Tree 2.Secondary Minimum Spanning Tree 3.Bottleneck.
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.
Fundamental Data Structures and Algorithms (Spring ’05) Recitation Notes: Graphs Slides prepared by Uri Dekel, Based on recitation.
Introduction to Graph Theory
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Minimum- Spanning Trees
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
CSCE 411 Design and Analysis of Algorithms Set 9: More Graph Algorithms Prof. Jennifer Welch Spring 2012 CSCE 411, Spring 2012: Set 9 1.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Proof of correctness of Dijkstra’s algorithm: Basically, we need to prove two claims. (1)Let S be the set of vertices for which the shortest path from.
Instructor: Lilian de Greef Quarter: Summer 2017
Shortest Paths and Minimum Spanning Trees
12. Graphs and Trees 2 Summary
CS 3343: Analysis of Algorithms
Lecture 12 Algorithm Analysis
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Shortest Path Graph represents highway system Edges have weights
The Greedy Approach Winter-2004 Young CS 331 D&A of Algo. Greedy.
Short paths and spanning trees
CS 583 Analysis of Algorithms
Lecture 12 Algorithm Analysis
Minimum Spanning Tree Algorithms
Shortest Paths and Minimum Spanning Trees
CSE332: Data Abstractions Lecture 18: Minimum Spanning Trees
Minimum Spanning Trees
Fundamental Structures of Computer Science II
離散數學 DISCRETE and COMBINATORIAL MATHEMATICS
Chapter 24: Single-Source Shortest Paths
Greedy Algorithms Comp 122, Spring 2004.
Chapter 24: Single-Source Shortest Paths
The Greedy Approach Young CS 530 Adv. Algo. Greedy.
Lecture 12 Algorithm Analysis
Winter 2019 Lecture 11 Minimum Spanning Trees (Part II)
Prim’s algorithm for minimum spanning trees
Single-Source Shortest Path & Minimum Spanning Trees
Greedy Algorithms (I) Greed, for lack of a better word, is good! Greed is right! Greed works! - Michael Douglas, U.S. actor in the role of Gordon Gecko,
Chapter 9: Graphs Spanning Trees
Minimum Spanning Trees
Autumn 2019 Lecture 11 Minimum Spanning Trees (Part II)
Presentation transcript:

COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000

Proof(Prim’s Th.) Proof (Prim’s Th.) It is true for k=0 (single node) Assume: it is true for T(k) (i.e. T(k) is subtree of min.span.tr T). Prove it for T(k+1)!. -At step k+1 let e is the smallest weight-> T(k+1) = T(k)+e. There are 2 options-> if e T-> T(k+1) is subtree min.sp.tr. Of T. We are ready! Assume e isn’t edge of T and show this cannot be ( it leads to contradiction) If e  T-> (T+e) should have cycle! (otherwise T+e is a tree but T is max) -> Consider this cycle in T+e (see Figure) -> f is an edge in the cycle that connects to T(k). -> we know w(e)  w(f) [we choose so in the Algorithm ~always the smallest] ^T spanning tree: w(^T) = w(T)+w(e)-w(f)  w(T)-> but T is minimal. This is a CONTRADICTION unless w(e)=w(f). ->[eT it should be] g.e.d.. Define ^T= T+e-f

Complexity Analysis of Prim’s Algorithm the algorithm has n-1 loops (for each covered vertex) the search in the loops for the minimal fronties edge O(n) For Large N This is Very Demanding -> There is ‘Better’ Algorithm Kruskal That can have -> O(e log e) (Kruskal) Time Complexity: -# of vertices This is better: If e<<n^2 (sparse graph) than Prim.

Algorithm 4.5.1 Prim’s Minimum Spanning Tree Scheme Input: a weighted connected graph G. Output: a minimum spanning tree T. Choose an arbitrary vertex s of graph G. Initialize the Prim tree T as vertex as s. Initialize the set of frontier edges for tree T as empty. While Prim tree T does not yet span G. Update the set of frontier edges for T. Let e be a frontier edges for T. Let e be a frontier edge for T with the smallest edge-weight. Let v be the non-tree endpoint of edge e. Add the edge e (and vertex v) to tree T. Return Prim tree T.

Optimality of Spanning Trees -> Prim (minimum spanning tree ~ weights) -> Dijkstra: Shortest Path: Shortest Path Problem: Let s and t two vertices of a (connected) weighted graph G. Find the path from s to t with minimum total weights Measuring of weight: distance (effort, time, …) Assume > 0 (positive) Idea: (similar to Prim’s) Grow a tree (Dijkstra tree D) from the vertex s At each iteration add a frontier edge which is as close as possible to s. -> dist[x] means: distance from node x to starting node s.

Theorem (Dijkstra) – Shortest Path T(j)- Dijkstra tree after j iterations (0  j  |V(G)| - 1) on a connected graph G. ->    T(j) : the unique s-v path in T(j) is the shortest path in G. Proof: by induction: -true for T(0) -Assume it’s true for T(0)! -Prove it for T(j+1)! Per definition: Q is the shortest path from s to y in T(j+1)! We have to show: it is the shortest also in G. Let R is any other path s-y in G. We have to know: length (R)  length (Q). We know length (Q)  length. -> Length ( R ) = length/ s->v->f) + length (k)  length (Q) + length (k) *draw image

Complexity of Dijkstra Minimum Path Algorithm - Efficiency : (O(n^2)) -we have n loops -each loop takes O(n) operations can be improved by adjusting the adjacency list O((e +n) log n) For sparse graphs: ~O(n log n)

Algorithm 4.5.2: Dijkstra’s Shortest Path Input: a weighted connected graph G whose edge-weights are nonnegative; and a vertex s of G. Output: a spanning tree T of G, rooted at vertex s, whose path from s to each vertex v is a shortest path from s to v in G; and a vertex-labeling giving the distance from s to each vertex. Initialize the Dijkstra tree T as a vertex s. Initialize the set of frontier edges for tree T as empty. Dist[s]:= 0 Write label 0 on vertex s. While Dijkstra tree T does not yet span G For each frontier edge e for T Let x be the labeled endpoint of edge e. Let y be the unlabeled endpoint of edge e. Add edge e (and vertex y) to tree T. Dist[y]:= P(e) Write label dist[y] on vertex y. Return Dijkstra tree T and its vertex labels.