1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 13 Instructor: Paul Beame.

Slides:



Advertisements
Similar presentations
Maximum flow Main goals of the lecture:
Advertisements

1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 19 Prof. Erik Demaine.
Introduction to Algorithms 6.046J/18.401J/SMA5503
Graph Algorithms - 3 Algorithm Design and Analysis Victor AdamchikCS Spring 2014 Lecture 13Feb 12, 2014Carnegie Mellon University.
Weighted Matching-Algorithms, Hamiltonian Cycles and TSP
Lecture 15. Graph Algorithms
Algorithms (and Datastructures) Lecture 3 MAS 714 part 2 Hartmut Klauck.
2 4 Theorem:Proof: What shall we do for an undirected graph?
Bart Jansen 1.  Problem definition  Instance: Connected graph G, positive integer k  Question: Is there a spanning tree for G with at least k leaves?
Epp, section 10.? CS 202 Aaron Bloomfield
 Theorem 5.9: Let G be a simple graph with n vertices, where n>2. G has a Hamilton circuit if for any two vertices u and v of G that are not adjacent,
Single Source Shortest Paths
all-pairs shortest paths in undirected graphs
UNC Chapel Hill Lin/Foskey/Manocha Steps in DP: Step 1 Think what decision is the “last piece in the puzzle” –Where to place the outermost parentheses.
Graphs and Finding your way in the wilderness
Analysis of Algorithms CS 477/677
Cpt S 223 – Advanced Data Structures Graph Algorithms: Introduction
12-Apr-15 Analysis of Algorithms. 2 Time and space To analyze an algorithm means: developing a formula for predicting how fast an algorithm is, based.
Greed is good. (Some of the time)
Lecture 17 Path Algebra Matrix multiplication of adjacency matrices of directed graphs give important information about the graphs. Manipulating these.
CSE 101- Winter ‘15 Discussion Section January 26th 2015.
 2004 SDU Lecture11- All-pairs shortest paths. Dynamic programming Comparing to divide-and-conquer 1.Both partition the problem into sub-problems 2.Divide-and-conquer.
Lecture 27. String Matching Algorithms 1. Floyd algorithm help to find the shortest path between every pair of vertices of a graph. Floyd graph may contain.
Lecture 21: Matrix Operations and All-pair Shortest Paths Shang-Hua Teng.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 9 Instructor: Paul Beame.
Lecture 22: Matrix Operations and All-pair Shortest Paths II Shang-Hua Teng.
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
Lecture 39 CSE 331 Dec 6, On Friday, Dec 10 hours-a-thon Atri: 2:00-3:30 (Bell 123) Jeff: 4:00-5:00 (Bell 224) Alex: 5:00-6:30 (Bell 242)
1 Advanced Algorithms All-pairs SPs DP algorithm Floyd-Warshall alg.
CSE 421 Algorithms Richard Anderson Lecture 4. What does it mean for an algorithm to be efficient?
Shortest Paths Definitions Single Source Algorithms
Algorithms All pairs shortest path
All-Pairs Shortest Paths
1 Dynamic Programming Jose Rolim University of Geneva.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 14 Instructor: Paul Beame.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 5 Instructor: Paul Beame TA: Gidon Shavit.
Lecture 11 CSE 331 Sep 25, Homeworks Please hand in your HW 2 now HW 3 and graded HW 1 at the end of class.
CS 473 All Pairs Shortest Paths1 CS473 – Algorithms I All Pairs Shortest Paths.
Directed graphs Definition. A directed graph (or digraph) is a pair (V, E), where V is a finite non-empty set of vertices, and E is a set of ordered pairs.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Algorithms: Design and Analysis Summer School 2013 at VIASM: Random Structures and Algorithms Lecture 3: Greedy algorithms Phan Th ị Hà D ươ ng 1.
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
Parallel Programming: All-Pairs Shortest Path CS599 David Monismith Based upon notes from multiple sources.
Shortest Path Algorithms. Definitions Variants  Single-source shortest-paths problem: Given a graph, finding a shortest path from a given source.
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
TU/e Algorithms (2IL15) – Lecture 12 1 Linear Programming.
All-pairs Shortest paths Transitive Closure
Shortest Path Problems
All-Pairs Shortest Paths (26.0/25)
Lecture 7 All-Pairs Shortest Paths
Randomized Algorithms CS648
Lecture 36 CSE 331 Nov 30, 2016.
Punya Biswas Lecture 15 Closest Pair, Multiplication
Lecture 24 CSE 331 Oct 29, 2012.
Shortest Path Problems
Richard Anderson Lecture 30 NP-Completeness
Problem Solving 4.
All pairs shortest path problem
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
Shortest Path Problems
Lecture 11 CSE 331 Sep 21, 2017.
Graphs G = (V, E) V are the vertices; E are the edges.
CSE 417: Algorithms and Computational Complexity
Lecture 11 CSE 331 Sep 22, 2016.
Winter 2019 Lecture 11 Minimum Spanning Trees (Part II)
Closures of Relations Epp, section 10.1,10.2 CS 202.
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
All Pairs Shortest Path Examples While the illustrations which follow only show solutions from vertex A (or 1) for simplicity, students should note that.
Lecture 37 CSE 331 Dec 3, 2018.
Presentation transcript:

1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 13 Instructor: Paul Beame

2 All-pairs shortest paths  If no negative-weight edges and sparse graphs run Dijsktra from each vertex O(nm log n)  What about other cases?

3 Floyd’s Algorithm Idea  Interior vertices in a path  Dijsktra’s Algorithm  at each step always computed shortest paths that only had interior vertices from a set S at each step  Floyd’s Algorithm  slowly add interior vertices on fixed schedule rather than depending on the graph v w interior vertices

4 Floyd’s Algorithm  Vertices V={v 1,...,v n }  Let D k [i,j] = length of shortest path from v i to v j that only allows {v 1,...,v k } as interior vertices  Note  D 0 [i,j] = weight of edge (v i,v j ) if (v i,v j )  E  if (v i,v j )  E  D n [i,j] = length of shortest path from v i to v j

5 Floyd’s Algorithm vivi vertices from v 1,...,v k vivi vivi vertices from v 1,...,v k-1 vivi Computing D k [i,j] Case 1: v k not used D k [i,j] = D k-1 [i,j]

6 Floyd’s Algorithm vjvj vkvk vertices from v 1,...,v k-1 Case 2: v k used vertices from v 1,...,v k-1 vivi

7 Floyd’s Algorithm vjvj vkvk vertices from v 1,...,v k-1 Case 2: v k used vertices from v 1,...,v k-1 vivi not on shortest path since no negative cycles

8 Floyd’s Algorithm vjvj vkvk vertices from v 1,...,v k-1 Case 2: v k used vivi vertices from v 1,...,v k-1 D k [i,j] = D k-1 [i,k] + D k-1 [k,j]

9 Floyd’s Algorithm  Floyd(G) D 0  weight matrix of G for k=1 to n do for i=1 to n do for i=1 to n do D k [i,j]  min{ D k-1 [i,j], D k-1 [i,k]+D k-1 [k,j]} endfor endfor endfor O(n 3 ) time O(n 2 ) storage by maintaining array for last two values of k

10 Multiplying Faster  On the first HW you analyzed our usual algorithm for multiplying numbers   (n 2 ) time  We can do better!  We’ll describe the basic ideas by multiplying polynomials rather than integers  Advantage is we don’t get confused by worrying about carries at first

11 Note on Polynomials  These are just formal sequences of coefficients so when we show something multiplied by x k it just means shifted k places to the left

12 Polynomial Multiplication  Given:  Degree n-1 polynomials P and Q  P = a n-1 x n-1 + a n-2 x n-2 + … + a 2 x 2 + a 1 x + a 0  Q = b n-1 x n-1 + b n-2 x n-2 + … + b 2 x 2 + b 1 x + b 0  Compute:  Degree 2n-2 Polynomial P  Q  P  Q = a n-1 b n-1 x 2n-2 + (a n-1 b n-2 + a n-2 b n-1 ) x 2n (a n-1 b i+1 +a n-2 b i a i+1 b n-1 ) x n+i a 0 b 0  Obvious Algorithm:  Compute all a i b j and collect terms   (n 2 ) time

13 Naive Divide and Conquer  Assume n is a power of 2  P = (a n-1 x n/2-1 + a n-2 x n/2-2 + … + a n/2 ) x n/2 + (a n/2-1 x n/ a 2 x 2 + a 1 x + a 0 ) = P 1 x n/2 + P 0  Q = Q 1 x n/2 + Q 0  P  Q = (P 1 x n/2 +P 0 )(Q 1 x n/2 +Q 0 ) = P 1 Q 1 x n +(P 1 Q 0 +P 0 Q 1 )x n/2 +P 0 Q 0  4 sub-problems of size n/2 + plus linear combining  T(n)=4T(n/2)+cn  Solution T(n) = O(n 2 )

14 Karatsuba’s Algorithm  A better way to compute the terms  Compute  P 0 Q 0  P 1 Q 1  (P 1 +P 0 )(Q 1 +Q 0 ) which is P 1 Q 1 +P 1 Q 0 +P 0 Q 1 +P 0 Q 0  Then  P 0 Q 1 +P 1 Q 0 = (P 1 +P 0 )(Q 1 +Q 0 ) - P 0 Q 0 - P 1 Q 1  3 sub-problems of size n/2 plus O(n) work  T(n) = 3 T(n/2) + cn  T(n) = O(n  ) where  = log 2 3 =