1 Sadna in Algorithms Haim Kaplan and Svetlana Olonetsky Tel Aviv University, fall 07/08.

Slides:



Advertisements
Similar presentations
Graph Algorithms - 4 Algorithm Design and Analysis Victor AdamchikCS Spring 2014 Lecture 14Feb 14, 2014Carnegie Mellon University.
Advertisements

Single Source Shortest Paths
§3 Shortest Path Algorithms Given a digraph G = ( V, E ), and a cost function c( e ) for e  E( G ). The length of a path P from source to destination.
§2 Topological Sort 〖 Example 〗 Courses needed for a computer science degree at a hypothetical university How shall we convert this list into a graph?
Everything you always wanted to know about spanners * *But were afraid to ask Seth Pettie University of Michigan, Ann Arbor.
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
1 Maximum Flow Networks Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘capacity’ u ij. Goal: Determine the maximum amount.
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
1 Efficient implementation of Dinic’s algorithm for maximum flow.
CPSC 411, Fall 2008: Set 9 1 CPSC 411 Design and Analysis of Algorithms Set 9: More Graph Algorithms Prof. Jennifer Welch Fall 2008.
Heaps Chapter 6 in CLRS. Motivation Dijkstra’s algorithm for single source shortest path Prim’s algorithm for minimum spanning trees.
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
1 Approximate Distance Oracles Mikkel Thorup AT&T Research Uri Zwick Tel Aviv University.
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.
Graph Algorithms: Shortest Path We are given a weighted, directed graph G = (V, E), with weight function w: E R mapping.
COS 423 Lecture 9 Shortest Paths II ©Robert E. Tarjan 2011.
1 Maximum flow: The preflow/push method of Goldberg and Tarjan (87)
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.
1 Exact and Approximate Distances in Graphs – A Survey Uri Zwick Tel Aviv University.
Approximate Distance Oracles for Geometric Spanner Networks Joachim Gudmundsson TUE, Netherlands Christos Levcopoulos Lund U., Sweden Giri Narasimhan Florida.
Princeton University COS 423 Theory of Algorithms Spring 2002 Kevin Wayne Greed: Shortest Path s 3 t
1 Heaps Chapter 6 in CLRS. 2 Motivation Router: Dijkstra’s algorithm for single source shortest path Prim’s algorithm for minimum spanning trees.
The Shortest Path Problem
1 Binomial heaps, Fibonacci heaps, and applications.
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Data Structures Week 9 Towards Weighted BFS So, far we have measured d s (v) in terms of number of edges in the path from s to v. Equivalent to assuming.
SPANNING TREES Lecture 21 CS2110 – Spring
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 6 Shortest Path Algorithms.
Near Optimal Streaming algorithms for Graph Spanners Surender Baswana IIT Kanpur.
Data Structures Haim Kaplan & Uri Zwick December 2013 Binary Heaps 1.
Approximate Distance Oracles Mikkel Thorup and Uri Zwick Presented By Shiri Chechik.
Minimum spanning trees (MST) Def: A spanning tree of a graph G is an acyclic subset of edges of G connecting all vertices in G. A sub-forest of G is an.
CSE 2331 / 5331 Topic 12: Shortest Path Basics Dijkstra Algorithm Relaxation Bellman-Ford Alg.
CSE 589 Part VI. Reading Skiena, Sections 5.5 and 6.8 CLR, chapter 37.
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!
A randomized linear time algorithm for graph spanners Surender Baswana Postdoctoral Researcher Max Planck Institute for Computer Science Saarbruecken,
Suppose G = (V, E) is a directed network. Each edge (i,j) in E has an associated ‘length’ c ij (cost, time, distance, …). Determine a path of shortest.
CSCE 411 Design and Analysis of Algorithms Set 9: More Graph Algorithms Prof. Jennifer Welch Spring 2012 CSCE 411, Spring 2012: Set 9 1.
ליאור שפירא, חיים קפלן וחברים
Shortest Paths and Minimum Spanning Trees
Graph Algorithms BFS, DFS, Dijkstra’s.
Spanning Trees Lecture 21 CS2110 – Fall 2016.
Shortest Path Problems
Greedy Algorithms / Dijkstra’s Algorithm Yin Tat Lee
Randomized Algorithms CS648
Shortest Paths.
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
Autumn 2015 Lecture 10 Minimum Spanning Trees
Shortest Path Problems
Shortest path algorithm
Analysis of Algorithms
Minimum Spanning Tree Algorithms
Shortest Paths and Minimum Spanning Trees
Approximate Distance Oracles
Algorithms (2IL15) – Lecture 7
Autumn 2016 Lecture 10 Minimum Spanning Trees
Graph Algorithms: Shortest Path
Shortest Paths.
CSE 417: Algorithms and Computational Complexity
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Maximum flow: The preflow/push method of Goldberg and Tarjan (87)
Analysis of Algorithms
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

1 Sadna in Algorithms Haim Kaplan and Svetlana Olonetsky Tel Aviv University, fall 07/08

2 Suggested topics Shortest path Maximum flow Min cost flow

3 What do you have to do: Choose algorithms to implement Understand them well Choose the graphs you’d run on The structure/language of your program What is the purpose ? Why do you do it ? There should be a goal, something that you do not know in advance, interesting graph classes

4 Inspiration There has been a lot of work recently on so called “algorithm engineering”: Three yearly conferences: 1)WAE 2)ALENEX 3)ESA (track B)

5 Some examples

6 Distances and Shortest Paths u v

7 There are many variations graph is undirected/directed weights: negative/nonnegative real/integer given pair(s)/single source/all pairs one shot/build a data structure or spaner exact/approximate randomized/deterministic

8 Dijkstra’s shortest path algorithm Let G = (V,E) be a weighted (weights are non-negative) undirected/directed graph, let s  V. Want to find the distance (length of the shortest path), d(s,v) from s to every other vertex. s

9 Dijkstra: Maintain an upper bound d(v) on d(s,v). Every vertex is either scanned, labeled, or unlabeled. Initially: d(s) = 0 and d(v) =  for every v  s. s is labeled and all others are unlabeled. Pick a labeled vertex with d(v) minimum. Make v scanned. For every edge (v,w) if d(v) + w(v,w) < d(w) then 1) d(w) := d(v) + w(v,w) 2) label w if it is not labeled already

10 Dijkstra’s shortest path algorithm (implementation) Maintain the labeled vertices in a heap, using d(v) as the key of v. We perform n delete-min operations and n insert operations on the heap. O(n log(n)) For each edge we may perform a decrease-key. With regular heaps O(m log (n)). But if you can do decrease-key in O(1) time then you can implement Dijkstra’s algorithm to run in O(n log(n) + m) time !

11 Dial’s implementation Assume that weights are small integers Maintain vertices in an array according to their distance label

12 An Example Initialize distance labels 0      Initialize array 1

13 Scan vertex     

14 Scan vertex     

15 Scan vertex     

16 Analysis Let C-1 be the maximum length of an arc What should be the length of the array ? What is the running time ? How can you do better ?

17 2-level buckets 0 C

18 2-level buckets 0 C

19 2-level buckets 0 C

20 Analysis What is the running time ? How can you do better ?

21 Goldberg et al Has done extensive experimental work on Dijkstra’s algorithm It may be interesting to repeat some of them ? Run on different graph classes, check new ideas, etc

22 k simple shortest paths a b e f t s c d g

23 Maintain a trie that described the paths found so far a b e f t s c d g t s sgt

24 The heap a b e f t s c d g t s sgt sabeft sgft

25 a b e f t s c d g t s sg sabeft g t gt gft

26 a b e f t s c d g t s sg g t gt gft t sabeft

27 a b e f t s c d g t s sg g t gt gft t sabeft saceft

28 a b e f t s c d g t s sg g t gt gft t t sa abeft a aceft sabdft sacdft

29 a b e f t s c d g t s sg g t gt gft t t sa a aceft sacdft t b ab bdft beft

30 a b e f t s c d g t s sg g t gt gft t t sa a aceft sacdft t b ab bdft beft

31 Point to point shortest paths

32 Running Dijkstra...

33 Bidirectional Dijkstra

34 Define potential function π(v) and modify lengths: – ℓ(v,w) = c(v,w) − π(v) + π(w) – ℓ(v,w): reduced cost of arc (v,w). All s-t paths change by same amount: π(t) − π(s). A* search: – Equivalent to Dijkstra on the modified graph: correct if ℓ(v,w) ≥ 0 (π is feasible). Take π(v) to be lower bounds on dist(v, t) A* search

35 Bidirectional A* Could be made to work Need to be careful: lower bounds must be consistent

36 Where do we get lower bounds ? Use landmarks dist(v,w) ≥ dist(A,w) − dist(A,v) dist(v,w) ≥ dist(v,A) − dist(w,A) A v w A v w

37 Query with landmarks

38 Landmark selection There has been research on it: –selection at preprocessing –selection for the query

39 Reach Reach of v with respect to P: reach(v, P) = min{ dist(s, v), dist(v, t) } Reach of v with respect to the whole graph: reach(v) = max P {reach(v, P)}, over all shortest paths P that contain v [Gutman’04]. Intuition: – vertices on highways have high reach; – vertices on local roads have low reach. v t s

40 How do you use reaches While scanning an edge (v,w): – If reach(w) < min{d(s, v) + ℓ(v,w), LB(w, t)}, then w can be pruned. t s w The lower bound is natural if the search is bidirectional v

41

42 Shortcuts Consider a sequence of vertices of degree two on the path below: – they all have high reach; s s t

43 Shortcuts s s t Add a shortcut: – single edge bypassing a path (with same length). – assume ties are broken by taking path with fewer nodes.

44 Shortcuts s s t Decrease reaches

45 Shortcuts s s t Can add more nested shortcuts 40

46 Shortcuts s s t Can add more nested shortcuts 40

47 Reaches + shortcuts

48 Combine reaches+shortcuts and landmarks

49 Spanners Let G be a weighted undirected graph. A subgraph H of G is a t -spanner of G iff  u,v  G,  H (u,v)  t  G (u,v). Awerbuch ’85 Peleg-Schäffer ‘89

50 Example

51 t-spanner Computing a t-spanner of smallest possible size is NP-complete. For a graph on n vertices, how large can a t-spanner be ? u v 2-spanner may require Ω(n 2 ) edges

52 Theorem For every k>1, every weighted undirected graph on n vertices has a (2k-1)-spanner with at most n 1+1/k edges. Tight for k=1,2,3,5. Conjectured to be tight for any k  equivalent to a girth conjecture of Erdös.

53 Proof/Algorithm: Consider the edges in non-decreasing order of weight. If an edge closes a cycle of length ≤ 2k discard it, otherwise add it. The resulting graph is a (2k-1)-spanner and it does not contain a cycle of length ≤ 2k. Such graph has at most n 1+1/k edges. [Althöfer, Das, Dobkin, Joseph, Soares ‘93]

54 If |cycle|  2k, then red edge can be removed.

55 k=2, Baswana & Sen

56 k=2, Baswana & Sen

57 k=2, Baswana & Sen

58 k=2, Baswana & Sen

59 k=2, Baswana & Sen

60 k=2, Baswana & Sen

61 k=2, Baswana & Sen

62 k=2, Baswana & Sen

63 k=2, Baswana & Sen

64 k=2, Baswana & Sen

65 k=2, Baswana & Sen

66 k=2, Baswana & Sen

67 k=2, Baswana & Sen

68 Analysis What is the average # of edges in the spanner ?

69 Correctness Why is this a 3-spanner ? Show: Where the weight of the red edges is smaller than the weight of the green one

70 Correctness This clearly holds if the edge became green at the first stage:

71 Correctness Otherwise, an edge (u,v’) must exist u v x

72 Correctness Otherwise, an edge (u,v’) must exist u v x v’

73 Implementation

74 (a,b)-Spanners Let G be an unweighted undirected graph. A subgraph H of G is an (a,b)-spanner of G iff  u,v  G,  H (u,v)  a  G (u,v) + b. (Dor-Halperin-Zwick ’96, a=1) Peleg-Elkin ’01 Baswana, Kavitha, Mehlhorn, Pettie ‘05 Thurup Zwick ‘06

75 Find interesting graph classes to test spanners on ? Should be relatively dense…

76 Other SP problems Distance oracles All pairs shortest paths geometric shortest paths/spanners time dependent shortest paths