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

Similar documents
CSC 1700 Analysis of Algorithms: Minimum Spanning Tree

CSC 8301 Design & Analysis of Algorithms: Warshall s, Floyd s, and Prim s algorithms

Greedy Approach: Intro

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

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

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

Week 11: Minimum Spanning trees

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

CIS 121 Data Structures and Algorithms Minimum Spanning Trees

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

CSE 100 Minimum Spanning Trees Prim s and Kruskal

Minimum Spanning Trees My T. UF

Week 12: Minimum Spanning trees and Shortest Paths

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

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

Minimum Spanning Trees

CSC 8301 Design & Analysis of Algorithms: Linear Programming

Announcements Problem Set 5 is out (today)!

COMP 182: Algorithmic Thinking Prim and Dijkstra: Efficiency and Correctness

Weighted Graphs and Greedy Algorithms

Minimum Spanning Trees

6.1 Minimum Spanning Trees

Minimum Spanning Trees

Minimum Spanning Trees. Minimum Spanning Trees. Minimum Spanning Trees. Minimum Spanning Trees

Minimum Spanning Trees

Priority queue ADT part 1

Undirected Graphs. Hwansoo Han

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

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

CS 6783 (Applied Algorithms) Lecture 5

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

The minimum spanning tree problem

Kruskal s MST Algorithm

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

Algorithm Design and Analysis

CS 161: Design and Analysis of Algorithms

Analysis of Algorithms, I

CSci 231 Final Review

CHAPTER 13 GRAPH ALGORITHMS

Introduction to Parallel & Distributed Computing Parallel Graph Algorithms

Design and Analysis of Algorithms

Introduction to Algorithms

2pt 0em. Computer Science & Engineering 423/823 Design and Analysis of Algorithms. Lecture 04 Minimum-Weight Spanning Trees (Chapter 23)

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

tree follows. Game Trees

Minimum Spanning Trees

Introduction to Algorithms

Minimum-Cost Spanning Tree. Example

Lecture 4: Graph Algorithms

Example. Minimum-Cost Spanning Tree. Edge Selection Greedy Strategies. Edge Selection Greedy Strategies

DESIGN AND ANALYSIS OF ALGORITHMS GREEDY METHOD

Graph Algorithms (part 3 of CSC 282),

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

Exam 3 Practice Problems

Partha Sarathi Manal

Minimum Spanning Tree

Parallel Graph Algorithms

CS61B, Fall 2002 Discussion #15 Amir Kamil UC Berkeley 12/5/02

Computer Science 385 Design and Analysis of Algorithms Siena College Spring Lab 8: Greedy Algorithms Due: Start of your next lab session

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

Minimum Spanning Trees

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

CSE 100: GRAPH ALGORITHMS

Lecture 5: Graph algorithms 1

COMP 355 Advanced Algorithms

Minimum spanning trees

CS200: Graphs. Rosen Ch , 9.6, Walls and Mirrors Ch. 14

Lecture 10: Analysis of Algorithms (CS ) 1

Greedy Algorithms. Textbook reading. Chapter 4 Chapter 5. CSci 3110 Greedy Algorithms 1/63

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

Lecture 6 Basic Graph Algorithms

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

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

Chapter 23. Minimum Spanning Trees

ALGORITHM DESIGN GREEDY ALGORITHMS. University of Waterloo

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

Lecture Notes for Chapter 23: Minimum Spanning Trees

23.2 Minimum Spanning Trees

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

Parallel Graph Algorithms

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

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

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

Announcements. HW4 due Friday. Summer 2016 CSE373: Data Structures & Algorithms 1

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths

Data Structures and Algorithms

CHAPTER 23. Minimum Spanning Trees

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

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

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

Chapter 9 Graph Algorithms

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

Minimum Spanning Trees

Introduction to Algorithms

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

11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions

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

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

CS 310 Advanced Data Structures and Algorithms

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

Transcription:

CSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms Professor Henry Carter Fall 2016

Recap Greedy algorithms iterate locally optimal choices to construct a globally optimal solution Minimum spanning trees are subgraphs that connect all vertices with the cheapest edge weights Prim s algorithm illustrates greedy design on adding vertices 2

Minimum Spanning Tree Given: a weighted, undirected, connected graph Find: a subgraph that connects all vertices with the cheapest edge weights Applications: network infrastructure, data set clustering, approximation algorithms 3

Greedy Approaches How could we greedily add vertices to the MST? How could we greedily add edges to the MST? 4

Kruskal s Algorithm Greedy approach to edges Maintains one set: edges in the MST (and counters for number of edges considered and number of edges in the MST) Add the minimum cost edge that does NOT form a cycle 5

Example b 1 d 3 4 4 6 a 5 c 5 e 6 1 8 f 6

Kruskal s Algorithm Kruskal(G) input : A weighted connected graph G = hv,ei. output: E T, the set of edges composing a minimum spanning tree of G. Sort E in nondecreasing order of the edge weights w(e i1 ) apple apple w(e i E ) E T ;; ecounter 0 k 0 while ecounter < V 1 do k k +1 if E T [ {e ik } is acyclic then E T E T [ {e ik }; ecounter ecounter +1 end end return E T 7

Finding Cycles Consider the starting vertices as disjoint sets When an edge is added, we take the union of the sets containing the endpoint vertices To check for cycles, ensure that the two endpoints are in disjoint subsets (i.e. disjoint subtrees) Three operations: Makeset(x) Find(x) Union(S 1, S 2 ) 8

Analysis Worst case: E iterations Testing for cycles (i.e., searching for disconnected components): O( E log V ) Union Find Sorting edges by weight: O( E log E ) 9

Practice b 1 d 5 3 4 6 a 6 c 2 e Find the MST using Kruskal s algorithm: 10

Shortest-Path Finding Recall: Floyd s algorithm Given a single source, find the shortest path to: a single destination all other vertices Single-source shortest-path problem 11

Dijkstra s Algorithm The shortest path from s to b is the shortest of the paths to all of b s neighbors plus the edge connecting b Considering the source, update the shortest path to all adjacent vertices Iterate for the next closest vertex u, saving the shortest distance to all of u s neighbors that passes through u 12

Example b 4 d 3 2 5 6 a 7 c 1 e 13

Reconstructing the shortest path b 4 d 3 2 5 6 a 7 c 1 e A 0 - B 3 A C 5 B E 6 C D 7 B 14

Dijkstra s Algorithm Dijkstra(G, s) input : A weighted connected graph G = hv,ei with nonnegative weights and a source vertex s. output: The length d v of a shortest path from s to v and its penultimate vertex p v for every vertex in V. Initialize(Q) for every vertex v 2 V do d v 1; p v null Insert(Q, v, d v ) end d s 0; Decrease(Q, s, d s ) V T ; for i 0 to V 1 do u DeleteMin(Q) V T V T [ {u } for every vertex u in V V T that is adjacent to u do if d u + w(u,u) <d u then d u d u + w(u,u); p u u Decrease(Q, u, d u ) end end end return V T 15

Analysis Similar analysis to Prim s algorithm Weight matrix and unordered priority queue: V 2 Min-heap: E log V Can be improved in theory with a Fibonacci heap 16

Practice b 4 d 3 2 5 6 a 7 c 4 e 17

Recap Greedy approach to graph problems iteratively searches for the locally optimal solution Single-source shortest-path problem Dijkstra s algorithm assumes the min distance to b is the min distance to b s neighbor plus the edge connecting b 18

Next Time... Levitin Chapter 9.4, 10.1 Remember, you need to read it BEFORE you come to class! Homework: 9.2: 1, 2, 4, 5 9.3: 2, 3, 4, 7 19