Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

Similar documents
Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

CS 310 Advanced Data Structures and Algorithms

Chapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Minimum Spanning Trees

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

Graphs and Network Flows IE411. Lecture 13. Dr. Ted Ralphs

Minimum Spanning Trees My T. UF

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 8 Lecturer: David Wagner February 20, Notes 8 for CS 170

22 Elementary Graph Algorithms. There are two standard ways to represent a

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

Algorithm Design (8) Graph Algorithms 1/2

22 Elementary Graph Algorithms. There are two standard ways to represent a

Algorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee

CS 6783 (Applied Algorithms) Lecture 5

Lecture 19. Broadcast routing

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm

Algorithms and Theory of Computation. Lecture 7: Priority Queue

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Lecture Summary CSC 263H. August 5, 2016

Algorithms and Theory of Computation. Lecture 5: Minimum Spanning Tree

Greedy Algorithms Part Three

CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li

CSE 373 MAY 10 TH SPANNING TREES AND UNION FIND

CSE 100: GRAPH ALGORITHMS

2.1 Greedy Algorithms. 2.2 Minimum Spanning Trees. CS125 Lecture 2 Fall 2016

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

2 A Template for Minimum Spanning Tree Algorithms

Greedy Algorithms. At each step in the algorithm, one of several choices can be made.

Greedy algorithms. Given a problem, how do we design an algorithm that solves the problem? There are several strategies:

Minimum Spanning Trees

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

Week 12: Minimum Spanning trees and Shortest Paths

CS521 \ Notes for the Final Exam

Lecture 6 Basic Graph Algorithms

6.1 Minimum Spanning Trees

Reference Sheet for CO142.2 Discrete Mathematics II

CSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

Weighted Graphs and Greedy Algorithms

Greedy Approach: Intro

Department of Computer Science and Engineering Analysis and Design of Algorithm (CS-4004) Subject Notes

CSE373: Data Structures & Algorithms Lecture 17: Minimum Spanning Trees. Dan Grossman Fall 2013

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

CSE 100 Minimum Spanning Trees Prim s and Kruskal

UNIT 3. Greedy Method. Design and Analysis of Algorithms GENERAL METHOD

Lecture Notes for Chapter 23: Minimum Spanning Trees

1 Shortest Paths. 1.1 Breadth First Search (BFS) CS 124 Section #3 Shortest Paths and MSTs 2/13/2018

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Minimum Spanning Trees

Minimum Spanning Trees

Chapter 23. Minimum Spanning Trees

CS711008Z Algorithm Design and Analysis

Theory of Computing. Lecture 10 MAS 714 Hartmut Klauck

Name: Lirong TAN 1. (15 pts) (a) Define what is a shortest s-t path in a weighted, connected graph G.

Graphs and Network Flows IE411. Lecture 21. Dr. Ted Ralphs

looking ahead to see the optimum

CSC 1700 Analysis of Algorithms: Minimum Spanning Tree

Design and Analysis of Algorithms

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

Undirected Graphs. Hwansoo Han

CISC 320 Midterm Exam

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n

CS711008Z Algorithm Design and Analysis

Minimum spanning trees

CS 561, Lecture 9. Jared Saia University of New Mexico

Spanning Tree. Lecture19: Graph III. Minimum Spanning Tree (MSP)

CSci 231 Final Review

Lecture 13: Minimum Spanning Trees Steven Skiena

Week 11: Minimum Spanning trees

Kruskal s MST Algorithm

1 Heaps. 1.1 What is a heap? 1.2 Representing a Heap. CS 124 Section #2 Heaps and Graphs 2/5/18

Chapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Dijkstra s algorithm for shortest paths when no edges have negative weight.

COMP 251 Winter 2017 Online quizzes with answers

Introduction to Algorithms

and 6.855J February 6, Data Structures

What is a minimal spanning tree (MST) and how to find one

Algorithms and Data Structures: Minimum Spanning Trees (Kruskal) ADS: lecture 16 slide 1

Introduction: (Edge-)Weighted Graph

Week 9 Student Responsibilities. Mat Example: Minimal Spanning Tree. 3.3 Spanning Trees. Prim s Minimal Spanning Tree.

Graphs and Network Flows IE411. Lecture 20. Dr. Ted Ralphs

Introduction to Algorithms

Course Review for Finals. Cpt S 223 Fall 2008

Sorting and Searching

Introduction to Algorithms

COP 4531 Complexity & Analysis of Data Structures & Algorithms

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

( D. Θ n. ( ) f n ( ) D. Ο%

Module 5 Graph Algorithms

Minimum Spanning Trees Ch 23 Traversing graphs

Lecture 13: Minimum Spanning Trees Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY

( ) n 3. n 2 ( ) D. Ο

These are not polished as solutions, but ought to give a correct idea of solutions that work. Note that most problems have multiple good solutions.

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

CSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms

Data Structures Brett Bernstein

n 2 ( ) ( ) + n is in Θ n logn

LECTURE 26 PRIM S ALGORITHM

Transcription:

Graphs and Network Flows ISE 411 Lecture 7 Dr. Ted Ralphs

ISE 411 Lecture 7 1 References for Today s Lecture Required reading Chapter 20 References AMO Chapter 13 CLRS Chapter 23

ISE 411 Lecture 7 2 Minimum Spanning Trees Optimality Conditions Kruskal s Algorithm Prim s Algorithm

ISE 411 Lecture 7 3 Combinatorial Optimization A combinatorial optimization problem consists of a ground set of elements E, an associated set F of subsets of E called the feasible subsets. A cost vector R E. The cost c(s) of a feasible subset is s S c s. The goal is to find a subset of minimum cost.

ISE 411 Lecture 7 4 Minimum Spanning Trees Recall that a spanning tree T of G is a connected acyclic subgraph that spans all the nodes of G. The total cost of a spanning tree is the sum of the costs of the arcs in the tree. Given an undirected graph G = (N, A) with n nodes and m arcs and with a length or cost c ij associated with each arc (i, j) A, the minimum spanning tree problem is to find a spanning tree with the smallest total cost (length). This is a combinatorial optimization problem.

ISE 411 Lecture 7 5 Optimality Conditions Cut Optimality Conditions Path Optimality Conditions Properties of a Spanning Tree For every non-tree arc (k, l), a spanning tree T contains a unique path from node k to node l. The arc (k, l) together with the unique path defines a cycle. If we delete any tree arc (i, j) from a spanning tree, we partition the node set into two subsets, which define a cut in the graph.

ISE 411 Lecture 7 6 Cut Optimality Conditions Theorem 1. [13.1] A spanning tree T is a minimum spanning tree if and only if for every tree arc (i, j) T, c ij c kl for every arc (k, l) contained in the cut formed by deleting arc (i, j) from T.

ISE 411 Lecture 7 7 Proof of Theorem 13.1 1. Show if T is a MST, then T must satisfy the Cut Optimality Conditions. 2. Show if any tree T satisfies the Cut Optimality Conditions, then T is a MST.

ISE 411 Lecture 7 8 Path Optimality Conditions Theorem 2. [13.3] A spanning tree T is a MST if and only if for every non-tree arc (k, l) of G, c ij c kl for every arc (i, j) contained in the path in T connecting nodes k and l.

ISE 411 Lecture 7 9 Proof of Theorem 13.3 1. Show if T is a MST, then T satisfies the Path Optimality Conditions. 2. Show if for every non-tree arc (k, l) of G c ij c kl for every arc (i, j) contained in the path in T connecting nodes k and l, then T is a MST.

ISE 411 Lecture 7 10 Algorithm Based on Cut Optimality Prim s algorithm is motivated by the cut optimality conditions. We build up the tree one edge at a time as one connected component. In each iteration, we will connect one more node to the current tree. We do this by adding the edge that is the minimum length edge across the cut induced by the current set of connected nodes. Why does this guarantee optimality? How do we do this?

ISE 411 Lecture 7 11 Prim s Algorithm algorithm Prim T = S = {1}; S = N {1} while ( S < n) do find arc (i, j) in [S, S] with minimum cost T = T {(i, j)} S = S {j}; S = S {j}

ISE 411 Lecture 7 12 Complexity Number of iterations? Dominant step of each iteration?

ISE 411 Lecture 7 13 Prim s Algorithm For each node j S d(j) = min cost of arcs in the cut incident to a node j S d(j) = min{c ij : (i, j) [S, S]} pred(j) = i such that c ij = min{c ij : (i, j) [S, S]. To find min cost arc, compute min{d(j) : j S}. Suppose ĵ is the min, then (pred(ĵ),j) is min cost arc. Move ĵ to S and update distance and predecessor labels for nodes adjacent to ĵ.

ISE 411 Lecture 7 14 Running Time of Prim s Algorithm Note that Prim s Algorithm is a graph search procedure. However, the procedure for determining the search order is more complex than previous ones. At each step, we need to update some node labels and then be able to determine the node with the minimum label. The key to implementing the procedure is an efficient data structure. What is the running time for a naive implementation?

ISE 411 Lecture 7 15 Implementation with Priority Queues The running time depends critically on how keep track of the minimum label as the algorithm progresses. To get a strongly polynomial time algorithm, we must use a more general data structure for maintaining a priority queue. For a given order set H, this data structure should support the operations push(item, value) (to add and change value of an item) peek() pop()

ISE 411 Lecture 7 16 Binary Heaps A binary heap is a balanced binary tree with additional structure that allows it to function efficiently as a priority queue. The additional structure needed to support these operations is that each node has a higher priority than either of its children. Balanced binary trees can be stored very efficiently in a single array. The root is stored in position 0. The children of the node in position i are stored in positions 2i + 1 and 2i + 2. This determines a unique storage location for every node in the tree and makes it easy to find a node s parent and children. Using an array, basic operations can be performed very efficiently.

ISE 411 Lecture 7 17 Creating the Heap Any node whose priority is higher than either of its children is said to satisfy the heap property. Consider a tree in which all nodes except for the root have the heap property. We can easily transform this into a tree in which every node has the heap property (how?). This operation is called heapify(). By calling heapify() on each node, starting at the lowest level and working upward, we can transform an unordered binary tree into a heap. This is how we create the initial heap. Note that this step is unnecessary for implementing Dijkstra s. Why?

ISE 411 Lecture 7 18 Operations on a Heap The node with the highest priority is always the root. To change the priority of a node To insert a node To delete a node What are the running times of these operations?

ISE 411 Lecture 7 19 Analyzing Prim s with a Binary Heap

ISE 411 Lecture 7 20 Algorithm Based on Path Optimality Kruskal s algorithm motivated by path optimality conditions. We build up the tree one edge at a time, but this time we build multiple components simultaneously. In each step, we will add the minimum edge that does not form a cycle with the edges already added. Why does this guarantee optimality? How do we implement it?

ISE 411 Lecture 7 21 Kruskal s Algorithm algorithm Kruskal sort edges in non-decreasing order of length LIST := while ( LIST < N 1 and unexamined edges) do e := unexamined edge with minimum length if adding e to LIST does not create a cycle add e to LIST else discard e

ISE 411 Lecture 7 22 Kruskal s Algorithm: Complexity The algorithm has two steps. Sorting the edge list: O(m log m) = O(m log n) Building the tree:?? To determine which edges we are allowed to add in each step requires a data structure for storing connected components. The data structure must support two operations. find(i, j): Are i and j in the same component? union(i, j): Merge the components i and j.

ISE 411 Lecture 7 23 Quick Find Implementation of Union-Find The simplest implementation involves an array of length n. We will maintain the array such that two items are in the same subset if and only if the array entries are equal. This makes the find(i, j) constant time, so we call this implementation quick find. How do we implement union(i, j)? What is the running time? Note that this could also be implemented using linked lists.

ISE 411 Lecture 7 24 Quick Union Implementation of Union-Find To speed up the union operation, we maintain the array in a different fashion. We will consider the i th entry of the array to be a pointer to another item. To perform find(i, j), Follow the pointers from nodes i and j until reaching a node that points to itself, called the representative If the same representative is reached from both nodes i and j, then they are in the same subset. To perform union(i, j), perform the find operation and then point the representative for i to the representative for j. What is the performance now?

ISE 411 Lecture 7 25 Weighted Quick Union Note that the quick union algorithm essentially builds a tree out of the nodes in each component, with the root being the representative. As in a heap, the running time of the find operation depends on the depth of the trees. Each union operation essentially connects two trees together by pointing the root of one tree to the root of the other. One way to limit the depth of the tree is to always point the smaller tree to the larger one. This ensures that each find takes less than log n steps. Note that we must now keep track of the number of nodes in each tree, but that s easy to do. Another approach is to keep track of the height of each tree and always point the shorter tree to the taller one.

ISE 411 Lecture 7 26 Path Compression Ideally, we would like each item to point directly to the representative of its subset. One possibility is to simply keep track of all the nodes encountered in the path to the root. After reaching the root, set all the nodes on the path to point to the root. This is easy to implement recursively and doesn t change the asymptotic running time. An easier method to implement is compression by halving, which is setting each node to point to its grandparent. Combining weighted quick union with path compression yields a total running time for connected components of approximately O(m).

ISE 411 Lecture 7 27 Analyzing Kruskal s with Optimized Union-Find