EECS 311: Chapter 9 Notes Chris Riesbeck EECS Northwestern.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

1 Minimum Spanning Tree Prim-Jarnik algorithm Kruskal algorithm.
EECS 311: Chapter 4 Notes Chris Riesbeck EECS Northwestern.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Spanning Trees.
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
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)
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Spanning Trees. Spanning trees Suppose you have a connected undirected graph –Connected: every node is reachable from every other node –Undirected: edges.
Chapter 9: Graphs Spanning Trees Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
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.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
CS 146: Data Structures and Algorithms July 21 Class Meeting
Graph (II) Shortest path, Minimum spanning tree GGuy
SPANNING TREES Lecture 21 CS2110 – Spring
Chapter 14 Graphs. © 2004 Pearson Addison-Wesley. All rights reserved Terminology G = {V, E} A graph G consists of two sets –A set V of vertices,
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
EECS 311: Chapter 6 Notes Chris Riesbeck EECS Northwestern.
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
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.
1 Chapter 4 Minimum Spanning Trees Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved.
Nattee Niparnan. Greedy If solving problem is a series of steps Simply pick the one that “maximize” the immediate outcome Instead of looking for the long.
Nattee Niparnan. Greedy If solving problem is a series of steps Simply pick the one that “maximize” the immediate outcome Instead of looking for the long.
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees  Definitions  Minimum spanning trees  3 greedy algorithms (incl. Kruskal’s & Prim’s)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Graphs Part II Lecture 7. Lecture Objectives  Topological Sort  Spanning Tree  Minimum Spanning Tree  Shortest Path.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
Graphs Upon completion you will be able to:
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
Prims Algorithm for finding a minimum spanning tree
Design and Analysis of Algorithms - Chapter 91 Greedy algorithms Optimization problems solved through a sequence of choices that are: b feasible b locally.
Graph Searching CSIT 402 Data Structures II. 2 Graph Searching Methodology Depth-First Search (DFS) Depth-First Search (DFS) ›Searches down one path as.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Graph Search Applications, Minimum Spanning Tree
Minimum Spanning Trees
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
May 12th – Minimum Spanning Trees
Minimum Spanning Tree Chapter 13.6.
Minimum Spanning Trees and Shortest Paths
CISC 235: Topic 10 Graph Algorithms.
Comp 245 Data Structures Graphs.
Graph Algorithm.
Minimum-Cost Spanning Tree
Minimum Spanning Tree.
Minimum Spanning Trees
Connected Components Minimum Spanning Tree
Minimum Spanning Tree.
Graphs Chapter 13.
MST - Prim’s Algorithm Greedy algorithm that “grows” an MST by repeatedly finding the lowest cost edge that will connect a new vertex to MST For every.
CSE373: Data Structures & Algorithms Lecture 12: Minimum Spanning Trees Catie Baker Spring 2015.
CSE373: Data Structures & Algorithms Lecture 20: Minimum Spanning Trees Linda Shapiro Spring 2016.
Minimum Spanning Trees
Spanning Trees.
Minimum-Cost Spanning Tree
Kruskal’s Algorithm for finding a minimum spanning tree
Chapter 23 Minimum Spanning Tree
Minimum-Cost Spanning Tree
Minimum Spanning Trees
Weighted Graphs & Shortest Paths
Minimum Spanning Trees (MSTs)
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Chapter 9: Graphs Spanning Trees
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 .
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

EECS 311: Chapter 9 Notes Chris Riesbeck EECS Northwestern

 Unless otherwise noted, all tables, graphs and code from Mark Allen Weiss' Data Structures and Algorithm Analysis in C++, 3 rd ed, copyright © 2006 by Pearson Education, Inc.

Cheapest Path Example

Dijkstra's Algorithm To find cheapest path from vertex s to vertex e: For all v cost[v] = ∞; known[v] = false; path[v] = - cost[s] = 0 Push s onto a priority queue pq that percolates vertices with lowest cost[] to the top. While pq not empty Pop v from pq If v = e, done. If not known[v] known[v] = true For all unknown successors w of v cvw = cost[v] + weight[v, w] If cvw < cost[w] cost[w] = cvw path[w] = v push w onto pq

Calculating All Cheapest Paths  Dijkstra's algorithm is |V| 2 to find all cheapest paths between 2 vertices.  To use it find all cheapest paths would be |V| 4.  Floyd's algorithm can do it in |V| 3.  Floyd's algorithm is simple. Complexity easy to determine. Why it works is not so obvious.

Floyd's Algorithm To find cheapest paths for all {u, v} in G: For all u, v in G cost[u, v] = weight[u, v]; path[u, v] = - For every vertex k For every vertex u For every vertex v ck = cost[u, k] + cost[k, v] If ck < cost[u, v] cost[u, v] = ck path[u, v] = k

Minimum Spanning Tree Example Graphs can have more than one MST but in this case, there's just this one. Note: Undirected graph.

Prim's Algorithm To find the Minimum Spanning Tree: For all v cost[v] = ∞; known[v] = false; path[v] = - cost[s] = 0 Push s onto a priority queue pq that percolates vertices with lowest cost[] to the top. While pq not empty Pop v from pq If not known[v] known[v] = true For all unknown successors w of v If weight[v, w] < cost[w] cost[w] = weight[v, w] path[w] = v push w onto pq Same as Dijkstra's algorithm except for what goes in cost[]

Kruskal's Algorithm To find the Minimum Spanning Tree: Set MST to an empty list of edges. Put all edges in priority queue pq that percolates cheapest edges to the top. Set ds to the set of singleton sets of all vertices. While pq not empty Pop edge from pq. If find(u) ≠ find(v) union(u, v) in ds. Add edge to MST. Cheap check to avoid cycles in MST. Edges need not be connected. A forest of trees is created.