Nondecreasing Paths in Weighted Graphs Or: How to optimally read a train schedule Virginia Vassilevska Carnegie Mellon UniversitySODA 2008.

Slides:



Advertisements
Similar presentations
Single Source Shortest Paths
Advertisements

IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Graphs CS-240/341. Graphs Used for representing many-to-many relationships –can take two forms directed (digraph) - a finite set of elements called vertices.
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
1 8-ShortestPaths Shortest Paths in a Graph Fundamental Algorithms.
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.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Shortest Paths Definitions Single Source Algorithms
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Nondecreasing Paths in Weighted Graphs Or: How to optimally read a train schedule Virginia Vassilevska.
Tirgul 13. Unweighted Graphs Wishful Thinking – you decide to go to work on your sun-tan in ‘ Hatzuk ’ beach in Tel-Aviv. Therefore, you take your swimming.
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.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
MIKKEL THORUP 1999 Journal of the ACM Undirected Single-Source Shortest Paths with Positive Integer Weights in Linear Time.
1 Shortest Path Algorithms. 2 Routing Algorithms Shortest path routing What is a shortest path? –Minimum number of hops? –Minimum distance? There is a.
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
1 Binomial heaps, Fibonacci heaps, and applications.
Graphs CS 400/600 – Data Structures. Graphs2 Graphs  Used to represent all kinds of problems Networks and routing State diagrams Flow and capacity.
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
Week -7-8 Topic - Graph Algorithms CSE – 5311 Prepared by:- Sushruth Puttaswamy Lekhendro Lisham.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
1 Fibonacci heaps, and applications. 2 Yet a better MST algorithm (Fredman and Tarjan) Iteration i: We grow a forest, tree by tree, as follows. Start.
SPANNING TREES Lecture 21 CS2110 – Spring
Dijkstra’s Algorithm Supervisor: Dr.Franek Ritu Kamboj
The single-source shortest path problem (SSSP) input: a graph G = (V, E) with edge weights, and a specific source node s. goal: find a minimum weight (shortest)
Week 12 - Monday.  What did we talk about last time?  Topological sort and cycle detection in directed graphs  Connectivity  Strong connectivity.
1 Prim’s algorithm. 2 Minimum Spanning Tree Given a weighted undirected graph G, find a tree T that spans all the vertices of G and minimizes the sum.
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!
1 22c:31 Algorithms Minimum-cost Spanning Tree (MST)
CSCE 411 Design and Analysis of Algorithms Set 9: More Graph Algorithms Prof. Jennifer Welch Spring 2012 CSCE 411, Spring 2012: Set 9 1.
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
Lecture 13 Shortest Path.
Graph Algorithms BFS, DFS, Dijkstra’s.
Binomial heaps, Fibonacci heaps, and applications
Chapter 7: Greedy Algorithms
Discrete Optimization Lecture 1
CS 3343: Analysis of Algorithms
Introduction to Graphs
Shortest Path Problems
Minimum-Cost Spanning Tree
Graphs Lecture 18 CS2110 – Fall 2009.
Graphs Chapter 11 Objectives Upon completion you will be able to:
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Minimum-Cost Spanning Tree
Minimum-Cost Spanning Tree
Shortest Path Problems
Minimum Spanning Tree Algorithms
Lecture 14 Shortest Path (cont’d) Minimum Spanning Tree
Algorithms Searching in a Graph.
Weighted Graphs & Shortest Paths
Shortest Path Problems
CSE 417: Algorithms and Computational Complexity
Binomial heaps, Fibonacci heaps, and applications
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Lecture 12 Shortest Path.
Lecture 14 Minimum Spanning Tree (cont’d)
Lecture 13 Shortest Path (cont’d) Minimum Spanning Tree
Minimum-Cost Spanning Tree
Data Structures and Algorithm Analysis Lecture 8
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Nondecreasing Paths in Weighted Graphs Or: How to optimally read a train schedule Virginia Vassilevska Carnegie Mellon UniversitySODA 2008

Traveling? Tomorrow after 8amAs early as possible!

Routes with Multiple Stops Chicago BWI 4pm – 8:30pm 1:30pm – 6:00pm 11:40pm – 1:25am 7:00pm – 8:45pm Los Angeles Las Vegas 8:35am – 11am 1:30pm – 4pm 5:05pm – 9:35pm 10:35pm – 12:35am

Scheduling You might need to make several connections. There are multiple possible stopover points, and multiple possible schedules. How do you choose which segments to combine?

arrival time weight;(Origin, flight) edges;(flight, Destination) edges;departure time weight;Nondecreasing path with minimum last edge? 12pm 9:35pm 11am 5pm4pm 8:45pm 7pm 9:30pm 10:35pm A vertex for each flight;A vertex for each city/airport; Graph-Theoretic Abstraction Chicago 4pm 1:30pm 11:40pm 7pm Los AngelesLas Vegas 8:35am 1:30pm 5:05pm 10:35pm BWI 8:30pm 6pm 12:35am 1:25am … … … … Graph:

Versions of the problem Single source – single destination Single source (every destination) All pairs ST All pairs – APNP Single source (every destination) – SSNP

History G. Minty 1958: graph abstraction and first algorithm for SSNP E. F. Moore 1959: a new algorithm for shortest paths, and SSNP – polytime – cubic time

History Dijkstra 1959 Fredman and Tarjan 1987 – Fibonacci Heaps implementation of Dijkstra’s; until now asymptotically fastest algorithm for SSNP. Nowadays – experimental research on improving Dijkstra’s algorithm implementation O(m+n log n) m – number of edges n – number of vertices

Our contributions Linear time algorithm for SSNP in the word-RAM model, O(m log log n) in comparison based model First truly subcubic algorithm for APNP

Talk Outline SSNP:  Two known algorithms  A new O(m log log n) algorithm  Linear time algorithm (on a RAM) APNP:  Brief outline of our approach

SSNP - Dijkstra’s algorithm Set U = V and T = { }. At each iteration, pick u from U minimizing d[u]. T = T U {u}, U = U \ {u}. For all edges (u, v),  If w(u,v) ≥ d[u], set d[v] = min (d[v], w(u,v)) u T U min d[u] d[u] v w(u,v) S Iterate:

Running time of Dijkstra Using Fibonacci Heaps, Dijkstra can be implemented in O(m+n log n) time. Optimal for Dijkstra’s algorithm – nodes visited in sorted order of their distance. The bottleneck are the n extract-mins.

More on Dijkstra’s Suppose we only maintain F vertices in the Fibonacci heaps. The rest we maintain in some other way. Then the runtime due to the Fibonacci heaps would be O(F log F + N(F)) where N(F) is the number of edges pointing to the F vertices. For F = m/log n, this is O(m)! F N(F)

ALG2: Depth First Search - Like DFS(v, d[v]): For all (v, u) with w(v, u) ≥ d[v]: Remove (v, u) from graph. d[u] = min (d[u], w(v,u)) DFS(u, d[u]) d[S] = - ∞, start with DFS(S, d[S]). v d[v]= u d[u]=4d[u]=3

Naive Runtime of DFS The number of times we call DFS(v, d[v]) for any particular v is at most indegree(v). Every such time we might have to check all outedges (w(v,u)≥ ? d[v]). Worst case running time: O(mn).

More on DFS Suppose for a node v and weight d[v] we can access each edge (v, u) with w(v, u)≥ d[v] in O(t) time. As each edge is accessed at most once, the runtime is O(m t). For each node, store its neighbors in a binary search tree w.r.t. outgoing weights. O(m log n) runtime

Combine Dijkstra with DFS Recall:  If F nodes used in Fibonacci heaps, then the Dijkstra runtime due to the heaps is O(F log F + N(F))  If DFS with binary search trees is run on a set of nodes T, the runtime is O(Σ v  T { deg in (v) log (deg out (v)) }) O(m log log n) for T = {v | deg out (v)<log n} ◄ O(m+n) for F = m/log n Low Degree High Degree {v | deg out (v) ≥ log n}

Idea Summary Run DFS on vertices of low degree < log n: O(m log log n) time. Put the O(m/log n) high degree nodes in Fibonacci heaps and run Dijkstra on them. Time due to Fibonacci heaps: O(m). We get O(m log log n). Better than O(m+n log n) for m = o(n log n/log log n).

But we wanted linear time… Fredman and Willard atomic heaps: After O(n) preprocessing, a collection of O(n) sets of O(log n) size can be maintained so that the following are in constant time:  Insert  Delete  Given w, return an element of weight ≥ w. outedges of low degree vertices RAM

Linear runtime Replace binary trees by atomic heaps. Time due to Dijkstra with Fibonacci Heaps on O(m/log n) elements is still O(m). Time due to DFS with atomic heaps:  inserting outedges into atomic heaps takes constant time per edge;  given d[v], accessing an edge with w(v,u) ≥ d[v] takes constant time. O(m+n) time overall! But how do we combine Dijkstra and DFS?

Linear Time Algorithm Stage 1: Initialize  Find all vertices v of degree ≥ log n and insert into Fibonacci Heaps with d[v] = ∞;  For all vertices u of degree < log n, add outedges into atomic heap sorted by weights.  This stage takes O(m+n) time. Insert S with d[S] = - ∞

22 Linear Time Algorithm Cont. Stage 2: Repeat: 1. Extract vertex v from Fibonacci heaps with minimum d[v] 2. For all neighbors u of v, if w(u,v) ≥ d[v]: 1. Update d[u] if w(v,u) < d[u] 2. Run DFS(u, d[u]) on the graph spanned by low degree vertices until no more can be reached 3. If Fib.heaps nonempty, go to 1. 3 Fibonacci Heaps

(min, ≤ )-matrix product C = A B: C[i, j] = min k { B[k, j] | A[i, k] ≤ B[k, j] } (( W W) W) … W) - min nondecreasing k times All Pairs Nondecreasing Paths (APNP) paths of length ≤ k ij AB Say W is the adjacency matrix: W[i, i] = -  and W[i,j] = w(i, j) for i ≠ j.

All Pairs Nondecreasing Paths cont. We give an algorithm for (min, ≤ )- product of n x n matrices running in O(n 2.8 ) time. Hence, APNP for paths of length at most k can be done in O(k n 2.8 ) time. We show how to find APNP for paths of length at least k in Õ(n 3 / k) time. → O(n 2.9 ) Algorithm for APNP.

Summary We gave the first linear time algorithm for the single source nondecreasing paths problem, and the first subcubic algorithm for APNP. Now you can read a train schedule optimally!

Single source shortest paths?  Our degree approach fails – finding a linear time algorithm is hardest on low degree graphs Shortest Nondecreasing Paths? d … … d’ … … … d … w1w1 wdwd w’ 1 w’ d’ wdwd w1w Directions for future work o(m log n)?

THANK YOU! The End.

Example S P Q a b c d U - Fibonacci Heap: S: -infinity P: infinity Q: infinity Other Distances: a: infinity b: infinity c: infinity d: infinity 5

S P Q a b c d U - Fibonacci Heap: P: infinity Q: infinity Other Distances: a: 5 b: 1 c: 3 d: infinity S: -infinity S – extract min from U 5 Example

S P Q a b c d U - Fibonacci Heap: P: 2 Q: infinity Other Distances: a: 5 b: 1 c: 3 d: infinity S: -infinity DFS(b, 1) 5 Example

DFS(a, 5) S P Q a b c d U - Fibonacci Heap: P: 2 Q: infinity Other Distances: a: 5 b: 1 c: 3 d: infinity S: -infinity DFS(c, 3) 3 5 Example

2 3 P – extract min from U S P Q a b c d U - Fibonacci Heap: Q: 3 Other Distances: a: 3 b: 1 c: 3 d: 2 S: -infinity P: 2 5 Example

2 3 S P Q a b c d U - Fibonacci Heap: Q: 3 Other Distances: a: 2 b: 1 c: 3 d: 2 S: -infinity P: 2 DFS(d, 2) 5 Example

2 3 S P Q a b c d U - Fibonacci Heap: Q: 3 Other Distances: a: 2 b: 1 c: 2 d: 2 S: -infinity P: 2 DFS(a, 2) 5 Example

2 3 S P Q a b c d U - Fibonacci Heap: Q: 3 Other Distances: a: 2 b: 1 c: 2 d: 2 S: -infinity P: 2 DFS(c, 2) 5 DFS(a, 3) Example

2 3 S P Q a b c d U - Fibonacci Heap: Other Distances: a: 2 b: 1 c: 2 d: 2 S: -infinity P: 2 Q: 3 5 Q – extract min from U Example

DFS Algorithm

Dijkstra Algorithm

A linear time hybrid

New York Atlanta Newark London Paris Frankfurt 7pm – 1:20pm 11:35pm – 1pm 5:30pm – 10:40am 7:45pm – 8:30pm 11:40am – 4:15pm

∞∞

Graph-Theoretic Abstraction City vertices and Train vertices Edges between origin and train and train and destination Weight on origin -> train edge is departure time Weight on train -> destination edge is arrival time

Fibonacci Heaps  Inserting n vertices initially takes O(n) time.  Updating the distance d[v] of a vertex v takes constant time.  Returning the vertex u minimizing d[u] takes logarithmic time.