Hannah Tang and Brian Tjaden Summer Quarter 2002

Slides:



Advertisements
Similar presentations
1 Discrete Structures & Algorithms Graphs and Trees: III EECE 320.
Advertisements

Minimum Spanning Tree CSE 331 Section 2 James Daly.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
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)
CSE 326: Data Structures Spanning Trees Ben Lerner Summer 2007.
CSE 421 Algorithms Richard Anderson Lecture 10 Minimum Spanning Trees.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 10 Instructor: Paul Beame.
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.
CSE 326: Data Structures Lecture #19 More Fun with Graphs Henry Kautz Winter Quarter 2002.
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.
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.
Data Structures and Algorithms Graphs Minimum Spanning Tree PLSD210.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
SPANNING TREES Lecture 21 CS2110 – Spring
Minimum Spanning Trees
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
UNC Chapel Hill Lin/Foskey/Manocha Minimum Spanning Trees Problem: Connect a set of nodes by a network of minimal total length Some applications: –Communication.
Dijkstra’s Algorithm. Announcements Assignment #2 Due Tonight Exams Graded Assignment #3 Posted.
Spanning Trees CSIT 402 Data Structures II 1. 2 Two Algorithms Prim: (build tree incrementally) – Pick lower cost edge connected to known (incomplete)
SPANNING TREES Lecture 20 CS2110 – Fall Spanning Trees  Definitions  Minimum spanning trees  3 greedy algorithms (incl. Kruskal’s & Prim’s)
SPANNING TREES Lecture 21 CS2110 – Fall Nate Foster is out of town. NO 3-4pm office hours today!
Minimum Spanning Trees CSE 373 Data Structures Lecture 21.
Minimum- Spanning Trees
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
CSE 326: Data Structures Lecture #23 Dijkstra and Kruskal (sittin’ in a graph) Steve Wolfman Winter Quarter 2000.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
Greedy Algorithms.
Minimum Spanning Trees
Instructor: Lilian de Greef Quarter: Summer 2017
May 12th – Minimum Spanning Trees
Minimum Spanning Trees
CSE373: Data Structures & Algorithms
Spanning Trees Lecture 21 CS2110 – Fall 2016.
Minimum Spanning Trees and Shortest Paths
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Data Structures & Algorithms Graphs
Autumn 2016 Lecture 11 Minimum Spanning Trees (Part II)
Discrete Mathematics for Computer Science
Minimum-Cost Spanning Tree
CSCE350 Algorithms and Data Structure
Minimum Spanning Tree.
Minimum Spanning Trees
Minimum Spanning Tree.
Autumn 2015 Lecture 11 Minimum Spanning Trees (Part II)
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.
CSE 373 Data Structures and Algorithms
Minimum-Cost Spanning Tree
CSE 373: Data Structures and Algorithms
Minimum-Cost Spanning Tree
Kruskal’s Minimum Spanning Tree Algorithm
CSE332: Data Abstractions Lecture 18: Minimum Spanning Trees
Minimum Spanning Tree.
Minimum Spanning Trees
CSE 373: Data Structures and Algorithms
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
The Greedy Approach Young CS 530 Adv. Algo. Greedy.
Winter 2019 Lecture 11 Minimum Spanning Trees (Part II)
Spanning Trees Lecture 20 CS2110 – Spring 2015.
CSE 373: Data Structures and Algorithms
CSE 332: Minimum 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 .
Data Structures and Algorithms
Minimum Spanning Trees
More Graphs Lecture 19 CS2110 – Fall 2009.
Autumn 2019 Lecture 11 Minimum Spanning Trees (Part II)
Presentation transcript:

Hannah Tang and Brian Tjaden Summer Quarter 2002 CSE 326: Data Structures Minimum Spanning Trees and The Dynamic Duo (Prim and Kruskal) Hannah Tang and Brian Tjaden Summer Quarter 2002

Some Applications: Moving Around Washington Okay, in the last lecture, we saw that this was a single-source shortest path problem, which was solvable by Dijkstra’s algorithm. Now, we’re going to look at another one of the graph applications we talked about earlier. What’s the fastest way from Seattle to Spokane? Use Dijkstra’s Algorithm!

Some Applications: Communication in Washington This slide should be review What’s the cheapest inter-city network?

Spanning Tree Spanning tree: a subset of the edges from a connected graph that… touches all vertices in the graph (spans the graph) forms a tree (is connected and contains no cycles) Minimum spanning tree: the spanning tree with the least total edge cost. 4 7 1 5 9 2 The previous problem is a minimum spanning tree problem. We have two primary ways of solving this problem deterministically. BTW, Which of these three is the minimum spanning tree? (The one in the middle)

Two Different Algorithms This is like a two-for-one deal! Prim’s is similar to Dijkstra’s in that it starts from one particular node, and then greedily grows a MST from that node Kruskal’s takes an entirely different technique by starting with a forest of minimum spanning trees and unioning those trees together … hmm … unioning … I wonder what data structure we’ll use? Prim’s Algorithm Almost identical to Dijkstra’s Kruskals’s Algorithm Completely different!

Prim’s Algorithm for Minimum Spanning Trees A node-oriented greedy algorithm (builds an MST by greedily adding nodes) Select a node to be the “root” and mark it as known While there are unknown nodes left in the graph Select the unknown node n with the smallest cost from some known node m Mark n as known Add (m, n) to our MST The proof of correctness and runtime is the same as Dijkstra’s, ie O(E log V) Runtime:

Prim’s Algorithm In Action B D F H G E 2 3 1 4 10 8 9 7 Start with ‘a’

Kruskal’s Algorithm for Minimum Spanning Trees An edge-oriented greedy algorithm (builds an MST by greedily adding edges) Initialize all vertices to unconnected While there are still unmarked edges Pick the lowest cost edge e = (u, v) and mark it If u and v are not already connected, add e to the minimum spanning tree and connect u and v Here’s how Kruskal’s works. This should look very familiar. Remember our algorithm for maze creation? Except that the edge order there was random, this is the same as that algorithm! Sound familiar? (Think maze generation.)

Kruskal’s Algorithm In Action B D F H G E 2 3 1 4 10 8 9 7 Therefore, this example should look a lot like maze creation. We test the cheapest edge first (and break ties by choosing the leftmost edge first) Since B and C are unconnected, we add the edge to the MST and union B and C.

Proof of Correctness We already showed this finds a spanning tree: That was part of our definition of a good maze. Proof by contradiction that Kruskal’s finds the minimum: Assume another spanning tree has lower cost than Kruskal’s Pick an edge e1 = (u, v) in that tree that’s not in Kruskal’s Kruskal’s tree connects u’s and v’s sets with another edge e2 But, e2 must have at most the same cost as e1! So, swap e2 for e1 (at worst keeping the cost the same) Repeat until the tree is identical to Kruskal’s: contradiction! QED: Kruskal’s algorithm finds a minimum spanning tree. We already know this makes a spanning tree because our maze generation algorithm made a spanning tree. But, does this find the minimum spanning tree? Let’s assume it doesn’t. Then, there’s some other better spanning tree. Let’s try and make that tree more like Kruskal’s tree. (otherwise, Kruskal’s would have considered and chosen e1 before ever reaching e2) BTW, this is another proof technique for showing that a greedy algorithm finds the global optimal. - For Dijkstra’s/Prim’s, we saw a proof of the type “greedy stays ahead” -- that is, we assume that there is some other algorithm which is optimal. Then we show that the greedy algorithm does the same thing (or better) as the optimal algorithm. - This time around, we use an “exchange argument” proof. We show that, through exchanges which do not affect the value of the greedy solution, that our greedy algorithm finds the optimal result.

Data Structures for Kruskal’s Algorithm |E| times: Pick the lowest cost edge… findMin/deleteMin |E| times: If u and v are not already connected… …connect u and v. What data structures do we need for this? Priority Queue and Disjoint Set Union/Find What about initialization? We need to put all the edges in a priority queue; we can do that fast with a buildHeap call: O(|E|) So, overall, the runtime is O(|E|ack(|E|,|V|) + |E|log|E|) Who knows what’s slower? Inverse ackermann’s or log? LOG! How much slower? TONS! One last little point: |E| is at most |V|2, but log|V|2 = 2 log |V|. So: O(|E|log|V|) find representative union Runtime: