Shortest Paths Autumn 2018 Shrirang (Shri) Mare - - PowerPoint PPT Presentation

shortest paths
SMART_READER_LITE
LIVE PREVIEW

Shortest Paths Autumn 2018 Shrirang (Shri) Mare - - PowerPoint PPT Presentation

CSE 373: Data Structures and Algorithms Shortest Paths Autumn 2018 Shrirang (Shri) Mare shri@cs.washington.edu Thanks to Kasey Champion, Ben Jones, Adam Blank, Michael Lee, Evan McCarty, Robbie Weber, Whitaker Brand, Zora Fung, Stuart Reges,


slide-1
SLIDE 1

Shortest Paths

CSE 373: Data Structures and Algorithms

Thanks to Kasey Champion, Ben Jones, Adam Blank, Michael Lee, Evan McCarty, Robbie Weber, Whitaker Brand, Zora Fung, Stuart Reges, Justin Hsia, Ruth Anderson, and many others for sample slides and materials ...

Autumn 2018 Shrirang (Shri) Mare shri@cs.washington.edu

slide-2
SLIDE 2

.. that can be solved efficiently (in polynomial time) 1. Shortest path – find a shortest path between two vertices in a graph 2. Minimum spanning tree – find subset of edges with minimum total weights 3. Matching – find set of edges without common vertices 4. Maximum flow – find the maximum flow from a source vertex to a sink vertex A wide array of graph problems that can be solved in polynomial time are variants of these above problems. In this class, we’ll cover the first two problems – shortest path and minimum spanning tree

Four classes of graph problem

CSE 373 AU 18 2

slide-3
SLIDE 3

BFS on a directed graph

Run Breadth First Search on this graph starting from s. What order are vertices placed on the queue? When processing a vertex insert neighbors in alphabetical order.

CSE 373 AU 18 3

s t v u x w y

1: function search(Graph G) 2:

mark all vertices as unknown

3:

toVisit.enqueue(first vertex)

4:

mark first vertex as known

5:

while toVisit is not empty do

6:

current = toVisit.dequeue()

7:

for v : current.outNeighbors() do

8:

if v is unknown then

9:

toVisit.enqueue(v)

10:

mark v as known

11:

end if

12:

end for

13:

visited.add(current)

14:

end while

15: end function

<latexit sha1_base64="y87xbtbAFONJkMc1kH2lF/va0=">AD6nicdVJLb9NAEHZsHsW8WjhyWRFVSi5R3ApRISFVQrT0gogSaU4qtbrcbzKetfsIyWy/Ce4ITjyp/g3rB0nSl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iF8JHezKetsZHvUC6386ap+eNJLvOS+cl07HCZzXzqnzwbl0Bg5xPbfrHrnHvO+ez+8n0uo2pqnjtb5v3+C7ARu0=</latexit>

Queue

slide-4
SLIDE 4

Q1: Do a BFS on this graph, starting at node A

CSE 373 AU 18 4

A B C D E

Add nodes to queue in alphabetical order Queue Add nodes to queue in reverse alphabetical order Queue

slide-5
SLIDE 5

Q2: Do a DFS on this graph, starting at node A

CSE 373 AU 18 5

A B C D E

Add nodes to stack in alphabetical order Stack Add nodes to stack in reverse alphabetical order Stack

slide-6
SLIDE 6

Shortest paths

How does Google Maps figure out this is the fastest way to get to office hours?

CSE 373 AU 18 6

slide-7
SLIDE 7

Representing maps as graphs

How do we represent a map as a graph? What are the vertices and edges?

CSE 373 AU 18 7

slide-8
SLIDE 8

Representing maps as graphs

CSE 373 AU 18 8

K R D P H S Question: Does this graph correctly model all the shown paths?

slide-9
SLIDE 9

Representing maps as graphs

CSE 373 AU 18 9

K R D P H S 4 1 2 2 4 3 5 Question: Does this graph correctly model all the shown paths? Not quite. Some paths are longer than others. So we use “weights” to capture that additional information.

slide-10
SLIDE 10

Shortest paths

CSE 373 AU 18 10

The len length of a path is the sum of the edge weights on that path. Shortest t Path th Probl blem Gi Given: a directed graph G and vertices s and t Fi Find: d: the shortest path from s to t

s w y u t v x 1 4 1 5 4 2 5 6 3

slide-11
SLIDE 11

Unweighted graphs

Let’s start with a simpler version: the edges are all the same weight (un unweigh ghted) If the graph is unweighted, how do we find a shortest paths?

CSE 373 AU 18 11

slide-12
SLIDE 12

Unweighted graphs

If the graph is unweighted, how do we find a shortest paths? What’s the shortest path from s to s?

  • Well….we’re already there.

What’s the shortest path from s to u or s to v?

  • Just go on the edge from s

From s to w, x, or y?

  • Can’t get there directly from s, if we want a length 2 path, have to go through u or v.

CSE 373 AU 18 12

s t v u y w x

slide-13
SLIDE 13

To find the set of vertices at distance k, just find the set of vertices at distance k-1, and see if any of them have an outgoing edge to an undiscovered vertex. Do we already know an algorithm that does something like that? Yes! BFS!

1: function bfsShortestPaths(Graph G, Vertex source) 2:

toVisit.enqueue(source)

3:

mark source as known

4:

source.dist = 0

5:

while toVisit is not empty do

6:

current = toVisit.dequeue()

7:

for v : current.outNeighbors() do

8:

if v is unknown then

9:

v.distance = current.distance + 1

10:

v.predecessor = current

11:

toVisit.enqueue(v)

12:

mark v as known

13:

end if

14:

end for

15:

end while

16: end function

<latexit sha1_base64="ZE89WJRyuIgAiLWDjRBcq3cxNg=">AEOXicdVNLb9NAEHYTHsW8WjhyWVFVagWK4kqICqlSJURLyhQklaKo2q9Hser2LtmH2kjywf4W/wSjtwQHPkDjB+JmrbsxZNvHt/MN5MgS7g23e6PlVb71u07d1fvufcfPHz0eG39yUBLqxj0mUykOg2ohoQL6BtuEjNFNA0SOAkmLwt/SdTUJpL8dnMhildCx4xBk1CJ2tr/xXT+AMRc5TcZScROnBVDb+T6B1awMioPIn0cS2VAmx41sS7yQ0WzmBy+JL4VIaiSPR8ARlyQurWicP1jQw0QIwdc9MB8cWCha3avz13p1RNmhxCNZkIeS7mvhruhCgD2SNd1z+JeQIkb0oSromQhkCamdmCj1mlQJQJc+YQambkPJCK5FPyZh7VkdZ8AD6OA6n01jYWOYrKAKxsRdXLou6lSadVS1Rgy3uLSgvoBfFuTsLFhMBAa2xikfdfnabLEk0vqfNOhEdR9cF5qm8lTI0S3N9EOHSTol7trbR7XSrR64bXmNsOM3r4Xm8kPJbIqNsoRqPfS6mRnlVBnOEsDerYaMsgkdwxBNQVPQo7w6y4JsIhKSCKeNJC6kQi9n5DTVepYGJmWZ3XV4I3+YbWRLujnIvMGhCsJopsghKS8sZJyBUwk8zQoAzH54ywmCrKDP4Tlnm+hRX4UyDxdFlWE6Jv3FXcM5kmlIR+njnJlOS5cUm6ZdDInOA2y5xzdxSaO+qrNeNwU7HQ/vjzsb+biP5qvPMe5sOZ7z2tl3js9p+w1qfWRetr61v7e/tn+1f7dx3aWmlynjpLr/3HyUEZ8E=</latexit><latexit sha1_base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tr/xXT+AMRc5TcZScROnBVDb+T6B1awMioPIn0cS2VAmx41sS7yQ0WzmBy+JL4VIaiSPR8ARlyQurWicP1jQw0QIwdc9MB8cWCha3avz13p1RNmhxCNZkIeS7mvhruhCgD2SNd1z+JeQIkb0oSromQhkCamdmCj1mlQJQJc+YQambkPJCK5FPyZh7VkdZ8AD6OA6n01jYWOYrKAKxsRdXLou6lSadVS1Rgy3uLSgvoBfFuTsLFhMBAa2xikfdfnabLEk0vqfNOhEdR9cF5qm8lTI0S3N9EOHSTol7trbR7XSrR64bXmNsOM3r4Xm8kPJbIqNsoRqPfS6mRnlVBnOEsDerYaMsgkdwxBNQVPQo7w6y4JsIhKSCKeNJC6kQi9n5DTVepYGJmWZ3XV4I3+YbWRLujnIvMGhCsJopsghKS8sZJyBUwk8zQoAzH54ywmCrKDP4Tlnm+hRX4UyDxdFlWE6Jv3FXcM5kmlIR+njnJlOS5cUm6ZdDInOA2y5xzdxSaO+qrNeNwU7HQ/vjzsb+biP5qvPMe5sOZ7z2tl3js9p+w1qfWRetr61v7e/tn+1f7dx3aWmlynjpLr/3HyUEZ8E=</latexit>

Unweighted graphs: Key Idea

CSE 373 AU 18 13

slide-14
SLIDE 14

Unweighted graphs

If the graph is unweighted, how do we find a shortest paths?

CSE 373 AU 18 14

s t v u y w x 1 1 2 2 2 3

1: function bfsShortestPaths(Graph G, Vertex source) 2:

toVisit.enqueue(source)

3:

mark source as known

4:

source.dist = 0

5:

while toVisit is not empty do

6:

current = toVisit.dequeue()

7:

for v : current.outNeighbors() do

8:

if v is unknown then

9:

v.distance = current.distance + 1

10:

v.predecessor = current

11:

toVisit.enqueue(v)

12:

mark v as known

13:

end if

14:

end for

15:

end while

16: end function

<latexit sha1_base64="ZE89WJRyuIgAiLWDjRBcq3cxNg=">AEOXicdVNLb9NAEHYTHsW8WjhyWVFVagWK4kqICqlSJURLyhQklaKo2q9Hser2LtmH2kjywf4W/wSjtwQHPkDjB+JmrbsxZNvHt/MN5MgS7g23e6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KeNJC6kQi9n5DTVepYGJmWZ3XV4I3+YbWRLujnIvMGhCsJopsghKS8sZJyBUwk8zQoAzH54ywmCrKDP4Tlnm+hRX4UyDxdFlWE6Jv3FXcM5kmlIR+njnJlOS5cUm6ZdDInOA2y5xzdxSaO+qrNeNwU7HQ/vjzsb+biP5qvPMe5sOZ7z2tl3js9p+w1qfWRetr61v7e/tn+1f7dx3aWmlynjpLr/3HyUEZ8E=</latexit>
slide-15
SLIDE 15

What about the target vertex?

CSE 373 AU 18 15

Given: a directed graph G and vertices s,t Find: the shortest path from s to t. Shortest Path Problem

BFS didn’t mention a target vertex… It actually finds the shortest path from s to every other vertex.

slide-16
SLIDE 16

Weighted graphs

Each edge should represent the “time” or “distance” from one vertex to another. Sometimes those aren’t uniform, so we put a weight on each edge to record that number. The length of a path in a weighted graph is the sum of the weights along that path. We’ll assume all of the weights are positive

  • For GoogleMaps that definitely makes sense.
  • Sometimes negative weights make sense. To

Today’s algorithm doesn’t work for those graphs

  • There are other algorithms that do work.

CSE 373 AU 18 16

slide-17
SLIDE 17

Weighted graphs: Take 1

BFS works if the graph is unweighted. Maybe it just works for weighted graphs too?

CSE 373 AU 18 17

s t v w u

What went wrong? When we found a shorter path from s to u, we needed to update the distance to v (and anything whose shortest path went through u) but BFS doesn’t do that.

1 20 1 1 1 ∞ ∞ ∞ ∞ x ∞ 1 1 20 21 2 22 3

slide-18
SLIDE 18

Weighted graphs: Take 2

You already do this all the time. In project 2, you reduced implementing a hashset to implementing a hashmap. Any time you use a library, you’re reducing your problem to the one the library solves. Can we reduce finding shortest paths on weighted graphs to finding them on unweighted graphs?

CSE 373 AU 18 18

Using an algorithm for Problem B to solve Problem A. Reduction (informally)

slide-19
SLIDE 19

Weighted graphs: A Reduction

Given a weighted graph, how do we turn it into an unweighted one without messing up the edge lengths?

CSE 373 AU 18 19

s u v t 2 2 2 1 1 s u v t s u v t 2 s u v t 2 2 2 1 1 2

Transform Input Transform Output Unweighted Shortest Paths

slide-20
SLIDE 20

Weighted graphs: A Reduction

What is the running time of our reduction on this graph? O(|V|+|E|) of the modified graph, which is…slow.

CSE 373 AU 18 20

Does our reduction even work on this graph? Ummm….

Tl;dr: If your graph’s weights are all small positive integers, this reduction might work great. Otherwise we probably need a new idea. s u v t 200 5000 5000 15 1 s u v t ! 0.5 5000 3 1

slide-21
SLIDE 21

Weighted graphs: Take 3

So we can’t just do a reduction. Instead let’s try to figure out why BFS worked in the unweighted case, and try to make the same thing happen in the weighted case. Why did BFS work on unweighted graphs? How did we avoid this problem: When we used a vertex u to update shortest paths we already knew the exact shortest path to u. So we never ran into the update problem So if we process the vertices in order of distance from s, we have a chance.

CSE 373 AU 18 21

s t v w u 1 20 1 1 1 3 x 1 1 21 2 22

slide-22
SLIDE 22

Weighted graphs: Take 3

Goal: Process the vertices in order of distance from s Idea: Have a set of vertices that are “known”

  • (we know at least one path from s to them).

Record an estimated distance

  • (the best way we know to get to each vertex).

If we process only the vertex closest in estimated distance, we won’t ever find a shorter path to a processed vertex.

CSE 373 AU 18 22

slide-23
SLIDE 23

Dijkstra’s algorithm

CSE 373 AU 18 23

s t v w u 1 20 1 1 1 x 1 Vertex Distance Predecessor Processed s w x u v t 1: function Dijkstra(Graph G, Vertex source) 2:

initialize distances to ∞

3:

mark source as distance 0

4:

mark all vertices unprocesed

5:

while there are unprocessed vertices do

6:

let u be the closest unprocessed vertex

7:

for each edge (u, v) leaving u do

8:

if u.dist + w(u,v) < v.dist then

9:

v.dist = u.dist + w(u,v)

10:

v.predecessor = u

11:

end if

12:

end for

13:

mark u as processed

14:

end while

15: end function

<latexit sha1_base64="ViDUyFTh8UWy6OFNNccAYBdi138=">AAAEKXicbVLbbtNAEHUTLsXcWnjkZURTqQhUJZUQfQCp4lb6VgRpK8VRtV6P4yXrtdlL2mDli/ga3rg88iPMOmkgKStZnp05Z+d24lIKY9vtHyuN5pWr166v3ghv3rp95+7a+r0jUzjNscsLWeiTmBmUQmHXCivxpNTI8ljicTx85ePHI9RGFOqjHZ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HPPO/8V6zqa7/Uqo0llUfJooddJry2uaFKSRWzkmg3FqXnDgGdOMW1L+YpaL6UyW3aVBR60Xie+S7hoVnvEiz5lKIhKI9UuoJpvQ9U1SZpJU7Tc8DGnQneWxXjaOdrY7ZL/f2djbnY18NXgQPAy2gk7wLNgL3gWHQTfgjZeNrPG5oZtfm9+a35s/p9DGyoxzP1g4zd9/AJyTW/w=</latexit>
slide-24
SLIDE 24

Dijkstra’s algorithm

CSE 373 AU 18 24

s t v w u 1 20 1 1 1 x 1 Vertex Distance Predecessor Processed s

  • Yes

w 1 s Yes x 2 w Yes u 3 x Yes v 4 u Yes t 5 v Yes 1: function Dijkstra(Graph G, Vertex source) 2:

initialize distances to ∞

3:

mark source as distance 0

4:

mark all vertices unprocesed

5:

while there are unprocessed vertices do

6:

let u be the closest unprocessed vertex

7:

for each edge (u, v) leaving u do

8:

if u.dist + w(u,v) < v.dist then

9:

v.dist = u.dist + w(u,v)

10:

v.predecessor = u

11:

end if

12:

end for

13:

mark u as processed

14:

end while

15: end function

<latexit sha1_base64="ViDUyFTh8UWy6OFNNccAYBdi138=">AAAEKXicbVLbbtNAEHUTLsXcWnjkZURTqQhUJZUQfQCp4lb6VgRpK8VRtV6P4yXrtdlL2mDli/ga3rg88iPMOmkgKStZnp05Z+d24lIKY9vtHyuN5pWr166v3ghv3rp95+7a+r0jUzjNscsLWeiTmBmUQmHXCivxpNTI8ljicTx85ePHI9RGFOqjHZfYz9lAiVRwZsl1ur7yK4pxIFTF5KDQwma54JNepx9Gb53iHlO9Fp+Gxmo2qfY1KzPYfwJHqC2ew7SKSRh9sMwiCCWsYFJ8QUiocqY4GrAFtCKhUjtuXeBypoczLjAzx0J7AcCkBKrcCv+KU6UuyMAkjI4zIREqm6EmPn0XQYrOGfOiJFpwECMQHrgsDBp7iYHn1G+hoULGM8BkgLDlnsDoEdHZSKgBOHrwIIXKbfty4TGcEYDirectGNW+ecbpFV7AEvZvnDaUoE9PKQkWRm9UcpDWP6piYQrOT2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iz5lKIhKI9UuoJpvQ9U1SZpJU7Tc8DGnQneWxXjaOdrY7ZL/f2djbnY18NXgQPAy2gk7wLNgL3gWHQTfgjZeNrPG5oZtfm9+a35s/p9DGyoxzP1g4zd9/AJyTW/w=</latexit> <latexit sha1_base64="ViDUyFTh8UWy6OFNNccAYBdi138=">AAAEKXicbVLbbtNAEHUTLsXcWnjkZURTqQhUJZUQfQCp4lb6VgRpK8VRtV6P4yXrtdlL2mDli/ga3rg88iPMOmkgKStZnp05Z+d24lIKY9vtHyuN5pWr166v3ghv3rp95+7a+r0jUzjNscsLWeiTmBmUQmHXCivxpNTI8ljicTx85ePHI9RGFOqjHZfYz9lAiVRwZsl1ur7yK4pxIFTF5KDQwma54JNepx9Gb53iHlO9Fp+Gxmo2qfY1KzPYfwJHqC2ew7SKSRh9sMwiCCWsYFJ8QUiocqY4GrAFtCKhUjtuXeBypoczLjAzx0J7AcCkBKrcCv+KU6UuyMAkjI4zIREqm6EmPn0XQYrOGfOiJFpwECMQHrgsDBp7iYHn1G+hoULGM8BkgLDlnsDoEdHZSKgBOHrwIIXKbfty4TGcEYDirectGNW+ecbpFV7AEvZvnDaUoE9PKQkWRm9UcpDWP6piYQrOT2hebA2Z9l+fKWW2qDBClSzs8XRto73drg9cNjozYyOYnUOSw9MoKbjLUVkumTG9Tru0/Yr5oUq/aWewZHzIBtgjU7EcTb+qZTiBTefnmVJTaaEs1N5/GRXLjRnnMSFzZjOzHPPO/8V6zqa7/Uqo0llUfJooddJry2uaFKSRWzkmg3FqXnDgGdOMW1L+YpaL6UyW3aVBR60Xie+S7hoVnvEiz5lKIhKI9UuoJpvQ9U1SZpJU7Tc8DGnQneWxXjaOdrY7ZL/f2djbnY18NXgQPAy2gk7wLNgL3gWHQTfgjZeNrPG5oZtfm9+a35s/p9DGyoxzP1g4zd9/AJyTW/w=</latexit>
slide-25
SLIDE 25

Implementation details

One of those lines of pseudocode was a little sketchy > let u be the closest unprocessed vertex What ADT have we talked about that might work here? Minimum Priority Queues!

CSE 373 AU 18 25

Min Priority Queue ADT

removeMin() – returns the element with the smallest priority, removes it from the collection

state behavior

Set of comparable values

  • Ordered based on “priority”

peekMin() – find, but do not remove the element with the smallest priority insert(value) – add a new element to the collection

slide-26
SLIDE 26

Making minimum priority queues (MPQ) work

They won’t quite work “out of the box”.

CSE 373 AU 18 26

Min Priority Queue ADT

removeMin() – returns the element with the smallest priority, removes it from the collection

state behavior

Set of comparable values

  • Ordered based on “priority”

peekMin() – find, but do not remove the element with the smallest priority insert(value) – add a new element to the collection

slide-27
SLIDE 27

Dijkstra’s algorithm

CSE 373 AU 18 27

s t v w u 1 20 1 1 1 x 1 Vertex Distance Predecessor Processed s

  • Yes

w 1 s Yes x 2 w Yes u 3 x Yes v 4 u Yes t 5 v Yes 1: function Dijkstra(Graph G, Vertex source) 2:

initialize distances to ∞

3:

mark source as distance 0

4:

mark all vertices unprocesed

5:

while there are unprocessed vertices do

6:

let u be the closest unprocessed vertex

7:

for each edge (u, v) leaving u do

8:

if u.dist + w(u,v) < v.dist then

9:

v.dist = u.dist + w(u,v)

10:

v.predecessor = u

11:

end if

12:

end for

13:

mark u as processed

14:

end while

15: end function

<latexit sha1_base64="ViDUyFTh8UWy6OFNNccAYBdi138=">AAAEKXicbVLbbtNAEHUTLsXcWnjkZURTqQhUJZUQfQCp4lb6VgRpK8VRtV6P4yXrtdlL2mDli/ga3rg88iPMOmkgKStZnp05Z+d24lIKY9vtHyuN5pWr166v3ghv3rp95+7a+r0jUzjNscsLWeiTmBmUQmHXCivxpNTI8ljicTx85ePHI9RGFOqjHZfYz9lAiVRwZsl1ur7yK4pxIFTF5KDQwma54JNepx9Gb53iHlO9Fp+Gxmo2qfY1KzPYfwJHqC2ew7SKSRh9sMwiCCWsYFJ8QUiocqY4GrAFtCKhUjtuXeBypoczLjAzx0J7AcCkBKrcCv+KU6UuyMAkjI4zIREqm6EmPn0XQYrOGfOiJFpwECMQHrgsDBp7iYHn1G+hoULGM8BkgLDlnsDoEdH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-28
SLIDE 28

Making minimum priority queues (MPQ) work

They won’t quite work “out of the box”. We don’t have an update priority method. Can we add one?

  • Percolate up!

To percolate u’s entry in the heap up we’ll have to get to it.

  • Each vertex need pointer to where it appears in the priority queue
  • I’m going to ignore this point for the rest of the lecture.

CSE 373 AU 18 28

Min Priority Queue ADT

removeMin() – returns the element with the smallest priority, removes it from the collection

state behavior

Set of comparable values

  • Ordered based on “priority”

peekMin() – find, but do not remove the element with the smallest priority insert(value) – add a new element to the collection DecreasePriority(e, p) – decreases the priority of element e down to p.

slide-29
SLIDE 29

1: function Dijkstra(Graph G, Vertex source)

. with MPQ

2:

initialize distances to ∞, source.dist = 0

3:

mark all vertices unprocessed

4:

initialize MPQ as a min priority queue; add source with priority 0

5:

while MPQ is not empty do

6:

u = MPQ.getMin()

7:

for each edge (u,v) leaving u do

8:

if u.dist + w(u,v) < v.dist then

9:

if v.dist == ∞ then

10:

MPQ.insert(v, u.dist + w(u, v))

11:

else

12:

MPQ.decreasePriority(v, u.dist + w(u,v))

13:

end if

14:

v.dist = u.dist + w(u,v)

15:

v.predecessor = u

16:

end if

17:

end for

18:

mark u as processed

19:

end while

20: end function

<latexit sha1_base64="YVFLN63fwlLlrJ6AzC10IuRh9Y=">AEznicbVPBbtNAEHWbACVQaEGCA5cRTaVURFSCVEJKlUqUHqolArSVoqjarOeJEvWa+PdQmWBUd+kS/gNxjHTmjS7sXjmXkz+97O9EMptGk2/6yslsp37t5bu1958HD90eONzSdnOrARxw4PZBd9JlGKR2jDASL8Imd+XeN4fH2bx8xgjLQL1xUxC7PlsqMRAcGbIdbm5+svt41CohMlhEAkz8gVPu61exf1oFc9ykvfi61ibiKXJUcTCERzV4Qwjg98hv0UK7mHg+6hMckUF4KR9mlbcz4YZBKGEUyKHwgekWGKowYTQNUVamAm1XpRo5FYR+aM6DPojEwKYEub0SGsiqMAjI0erdUp6bANDwhYIwEhmXCXyzaPEtM8r+sD0hvM4tTsfCYmQZHihQUG0A/NZM7A0q0o2BiOR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LHPeFutaM9jrJUKF1qDieaOBldm0Z4tH8x8hN3JCBuNEXnDgIxYxbmg9F7vM1EmX3aFGS9QDL2NJ/xEqvOK0fEx5Lm2kyR4hSbehk5Gkzn2EqV/zSoWEbi3LetM420yD7d3TrYKyRfc14L52a03LeOAfOJ6ftdBy+re0XnpWel5ul+NyWv6Zp6uFJinzsIp/4HDlCNTQ=</latexit>

Running time analysis

CSE 373 AU 18 29

slide-30
SLIDE 30

Algorithm/Author Time complexity Year Ford !( # $ % ) 1956 Bellman-Ford. Shimbel !( # % ) 1958 Dijkstra’s algorithm with binary heap '( ( )*+ , + , )*+ |,|) 1959 Dijkstra’s algorithm with Fibonacchi heap !( % + # log |#|) 1984 Gabow’s algorithm !( % + # log |#|) 1990 Thorup !( % + # log log |#|) 2004

History of shortest path algorithms

CSE 373 AU 18 30

History of shortest path algorithms. In this class, from this table, you are expected to know only Dijkstra’s algorithm with binary heap and its time complexity. You are not expected to know the other algorithms or their time complexities.

slide-31
SLIDE 31

Other applications of shortest paths

Shortest path algorithms are obviously useful for GoogleMaps. The wonderful thing about graphs is they can encode arbi bitr trary relationships among

  • bjects.

I don’t care if you remember this problem I don’t care if you remember how we apply shortest paths. I just want you to see that these algorithms have non-obvious applications.

CSE 373 AU 18 31

slide-32
SLIDE 32

Other applications: Maximum probability path

CSE 373 AU 18 32

Given: a directed graph G, where each edge weight is the probability of successfully transmitting a message across that edge Find: the path from s to t with maximum probability of message transmission Maximum Probability Path

I have a message I need to get from point s to point t. But the connections are unreliable. What path should I send the message along so it has the best chance of arriving? s u v t 0.6 0.8 0.97 0.7 0.2

slide-33
SLIDE 33

Robot navigation Urban traffic planning Tramp steamer problem Optimal pipelining of VLSI chips Operator scheduling Subroutine in higher level algorithms Exploiting arbitrage opportunities in currency exchanges Open shortest path first routing protocol for IP Optimal truck routing through given traffic congestion

Other applications of shortest paths

CSE 373 AU 18 33