CSC 1700 Analysis of Algorithms: Warshall s and Floyd s algorithms

Similar documents
Chapter 8 Dynamic Programming

Design and Analysis of Algorithms

All-Pairs Shortest Paths

Chapter 8 Dynamic Programming

Chapter 9: Relations Relations

CS173 Lecture B, November 3, 2015

Analysis of Algorithms I: All-Pairs Shortest Paths

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

Single Source Shortest Paths

Relations Graphical View

Partha Sarathi Mandal

Complexity Theory of Polynomial-Time Problems

Notes. Relations. Introduction. Notes. Relations. Notes. Definition. Example. Slides by Christopher M. Bourke Instructor: Berthe Y.

CMPS 6610 Fall 2018 Shortest Paths Carola Wenk

CS 241 Analysis of Algorithms

Universal Algebra and Computational Complexity Lecture 1

CSC 1700 Analysis of Algorithms: P and NP Problems

Math.3336: Discrete Mathematics. Chapter 9 Relations

Module 1: Analyzing the Efficiency of Algorithms

Dynamic Programming. p. 1/43

CSC 8301 Design & Analysis of Algorithms: Lower Bounds

Lecture 11. Single-Source Shortest Paths All-Pairs Shortest Paths

CSCE 551 Final Exam, April 28, 2016 Answer Key

Computational Complexity for Algebraists

p 3 p 2 p 4 q 2 q 7 q 1 q 3 q 6 q 5

EE263 Review Session 1

Technische Universität München, Zentrum Mathematik Lehrstuhl für Angewandte Geometrie und Diskrete Mathematik. Combinatorial Optimization (MA 4502)

CS 410/584, Algorithm Design & Analysis, Lecture Notes 4

Module 1: Analyzing the Efficiency of Algorithms

Rela%ons and Their Proper%es. Slides by A. Bloomfield

Max-plus algebra. Max-plus algebra. Monika Molnárová. Technická univerzita Košice. Max-plus algebra.

Section Summary. Relations and Functions Properties of Relations. Combining Relations

Advanced topic: Space complexity

(c) Give a proof of or a counterexample to the following statement: (3n 2)= n(3n 1) 2

Note that M i,j depends on two entries in row (i 1). If we proceed in a row major order, these two entries will be available when we are ready to comp

Optimization Prof. A. Goswami Department of Mathematics Indian Institute of Technology, Kharagpur. Lecture - 20 Travelling Salesman Problem

Dynamic Programming. Prof. S.J. Soni

Determine the size of an instance of the minimum spanning tree problem.

Lecture Notes Each circuit agrees with M on inputs of length equal to its index, i.e. n, x {0, 1} n, C n (x) = M(x).

Discrete Optimization 2010 Lecture 2 Matroids & Shortest Paths

Introduction to Kleene Algebras

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu

CS1800: Mathematical Induction. Professor Kevin Gold

Lecture 2: Divide and conquer and Dynamic programming

Non-Interactive Zero Knowledge (II)

Discrete Structures, Final Exam

University of Toronto Scarborough. Aids allowed: None... Duration: 3 hours.

Definition A finite Markov chain is a memoryless homogeneous discrete stochastic process with a finite number of states.

Algorithm Design Strategies V

Optimal Tree-decomposition Balancing and Reachability on Low Treewidth Graphs

Dynamic Programming: Shortest Paths and DFA to Reg Exps

Mathematics for Decision Making: An Introduction. Lecture 8

CMPSCI 311: Introduction to Algorithms Second Midterm Exam

CSE200: Computability and complexity Space Complexity

CIS (More Propositional Calculus - 6 points)

P is the class of problems for which there are algorithms that solve the problem in time O(n k ) for some constant k.

CS 470/570 Dynamic Programming. Format of Dynamic Programming algorithms:

iretilp : An efficient incremental algorithm for min-period retiming under general delay model

SOLUTION: SOLUTION: SOLUTION:

Computational Intractability 2010/4/15. Lecture 2

NP and Computational Intractability

R ij = 2. Using all of these facts together, you can solve problem number 9.

Lecture 7: Shortest Paths in Graphs with Negative Arc Lengths. Reading: AM&O Chapter 5

Ngày 20 tháng 7 năm Discrete Optimization Graphs

Design and Analysis of Algorithms April 16, 2015 Massachusetts Institute of Technology Profs. Erik Demaine, Srini Devadas, and Nancy Lynch Quiz 2

Query Optimization: Exercise

Breadth First Search, Dijkstra s Algorithm for Shortest Paths

8.5 Sequencing Problems

Find: a multiset M { 1,..., n } so that. i M w i W and. i M v i is maximized. Find: a set S { 1,..., n } so that. i S w i W and. i S v i is maximized.

Theory of Computation Time Complexity

12. Cholesky factorization

Calculating Frobenius Numbers with Boolean Toeplitz Matrix Multiplication

Regular Expressions and Language Properties

Efficient Enumeration of Regular Languages

Informatique Fondamentale IMA S8

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University

Announcements. CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis. Today. Mathematical induction. Dan Grossman Spring 2010

Definition: A binary relation R from a set A to a set B is a subset R A B. Example:

REVIEW QUESTIONS. Chapter 1: Foundations: Sets, Logic, and Algorithms

On the Exponent of the All Pairs Shortest Path Problem

CHAPTER 1. Relations. 1. Relations and Their Properties. Discussion

Lecture 13. More dynamic programming! Longest Common Subsequences, Knapsack, and (if time) independent sets in trees.

Dynamic Programming: Shortest Paths and DFA to Reg Exps

Analysis of Algorithms. Outline. Single Source Shortest Path. Andres Mendez-Vazquez. November 9, Notes. Notes

Lecture Notes for Chapter 25: All-Pairs Shortest Paths

Section Summary. Sequences. Recurrence Relations. Summations Special Integer Sequences (optional)

Combinatorial optimization problems

Space-Bounded Communication Complexity

Generalized Splines. Madeline Handschy, Julie Melnick, Stephanie Reinders. Smith College. April 1, 2013

CSC Design and Analysis of Algorithms. Lecture 1

Let us first give some intuitive idea about a state of a system and state transitions before describing finite automata.

CS 301: Complexity of Algorithms (Term I 2008) Alex Tiskin Harald Räcke. Hamiltonian Cycle. 8.5 Sequencing Problems. Directed Hamiltonian Cycle

C241 Homework Assignment 7

1 Primals and Duals: Zero Sum Games

Dynamic Programming. Data Structures and Algorithms Andrei Bulatov

Notes for Lecture 14

Dynamic Programming( Weighted Interval Scheduling)

Problem One: Order Relations i. What three properties does a binary relation have to have to be a partial order?

Lab 2 Worksheet. Problems. Problem 1: Geometry and Linear Equations

Complex Networks CSYS/MATH 303, Spring, Prof. Peter Dodds

Transcription:

CSC 1700 Analysis of Algorithms: Warshall s and Floyd s algorithms Professor Henry Carter Fall 2016

Recap Space-time tradeoffs allow for faster algorithms at the cost of space complexity overhead Dynamic programming achieves this by saving the result of overlapping subproblems Can be executed bottom-up or top-down (using memory functions) 2

Digraphs Revisited Recall: directed graphs New feature: edge weights Applications: scheduling, process flow, revision history 3

Transitive Closure Is node b reachable from node a? Consider all pairs (a,b) Store results in an n x n matrix of {0,1} 4

Example Graph A B a 0 1 0 0 a 1 1 1 1 b 0 0 0 1 b 1 1 1 1 C D c 0 0 0 0 d 1 0 1 0 c 0 0 0 0 d 1 1 1 1 5

BFS/DFS Approach The transitive closure from a to any other node can be found through graph traversal Repeating for all nodes yields the complete closure matrix How could we apply dynamic programming? 6

Warshall s Algorithm Construct transitive closure using a series of matrices Matrix k considers paths through G traversing nodes 1,,k If a path exists from i to k and from k to j, mark a path from i to j R 0 is the paths between each vertex with no intermediate vertices (i.e., the adjacency matrix) 7

Rule for Changing 0 to 1 k j k 1 i 1 0 8

Example Application a 0 1 0 0 b 0 0 0 1 c 0 0 0 0 d 1 0 1 0 9

Example Application a 0 1 0 0 b 0 0 0 1 c 0 0 0 0 d 1 0 1 0 10

Example Application a 0 1 0 0 b 0 0 0 1 c 0 0 0 0 d 1 1 1 0 11

Example Application a 0 1 0 1 b 0 0 0 1 c 0 0 0 0 d 1 1 1 1 12

Example Application a 0 1 0 1 b 0 0 0 1 c 0 0 0 0 d 1 1 1 1 13

Example Application a 1 1 1 1 b 1 1 1 1 c 0 0 0 0 d 1 1 1 1 14

Algorithm Warshall(A[1,...,n,1,...,n]) input : The adjacency matrix A with n vertices. output: The transitive closure of the digraph. R (0) A for k 1 to n do for i 1 to n do for j 1 to n do R (k) [i, j] R (k 1) [i, j] or (R (k 1) [i, k] and R (k 1) [k, j]) end end end return R (n) 15

Speeding Things Up More efficient inner loop Treat rows as bit strings and apply boolean operations simultaneously Combine matrices into one 16

All-Pairs Shortest Paths Given a weighted digraph, find the shortest path from a to b Solve for all pairs (a,b) Stored in an n x n integer distance matrix 17

Example Graph A 2 B a 0 3 a 0 10 3 4 3 C 7 1 6 D b 2 0 c 7 0 1 d 6 0 b 2 0 5 6 c 7 7 0 1 d 6 16 9 0 18

Floyd s Algorithm Construct the distance matrix using a series of matrices Matrix k considers paths through G that traverse any vertex numbered 1,,k If there is a path from i to k and from k to j, we compare it to the current shortest path and (possibly) update the distance R0 is the distance between each node with no intermediate vertices (i.e., the edge weight matrix) 19

Rule for Updating Distance k j k 3 i 2 20

Example Application a 0 3 b 2 0 c 7 0 1 d 6 0 21

Example Application a 0 3 b 2 0 c 7 0 1 d 6 0 22

Example Application a 0 3 b 2 0 5 c 7 0 1 d 6 9 0 23

Example Application a 0 3 b 2 0 5 c 9 7 0 1 d 6 9 0 24

Example Application a 0 10 3 4 b 2 0 5 6 c 9 7 0 1 d 6 16 9 0 25

Example Application a 0 10 3 4 b 2 0 5 6 c 7 7 0 1 d 6 16 9 0 26

Algorithm Floyd(W [1,...,n,1,...,n]) input : The weight matrix W. output: The distance matrix of the shortest paths lengths. D W for k 1 to n do for i 1 to n do for j 1 to n do D[i, j] min(d[i, j],d[i, k]+d[k, j]) end end end return D 27

Practice Apply Warshall s algorithm to the following adjacency matrix: 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 28

Recap Transitive closure and all-pairs shortest paths problems Warshall s and Floyd s algorithms use dynamic programming to store intermediate results in a series of matrices We will revisit shortest-paths in the next chapter 29

Next Time... Levitin Chapter 9.1-9.2 Remember, you need to read it BEFORE you come to class! Homework: 8.4: 1, 2, 3, 6, 7 30