dijkstra’s algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/cool man...dijkstra’s algorithm,...

36
Dijkstra’s Algorithm Austin Saporito and Charlie Rizzo

Upload: others

Post on 16-Dec-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Dijkstra’s Algorithm

Austin Saporito and Charlie Rizzo

Page 2: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Test Questions

1. What is the run time complexity of Dijkstra’s algorithm?

2. What case is Dijkstra’s algorithm best used for?

3. What was the Dijkstra’s algorithm a rediscovery of?

Page 3: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Austin Saporito

● I wrecked the same car twice in one month (same

month I bought it)

● I’ve been slimed on Nickelodeon

● I have eaten 56 chicken nuggets in one hour

● I’ve been to Iceland

● I have an earring

● I did 2 of my own tattoos

● Wanted to be a dinosaur when I grew up

● I am doing this presentation in my underwear rn

Page 4: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra
Page 5: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Charlie Rizzo

● Born in New Jersey

● 75% Italian + 25% Scottish

● Moved 15+ times

● I don’t like long walks on the beach

○ I burn very easily

● I wear hearing aids

● Been to Italy and Greece

○ Hiked up Mt. Olympus

Page 6: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Charlie Rizzo

● Born in New Jersey

● 75% Italian + 25% Scottish

● Moved 15+ times

● I don’t like long walks on the beach

○ I burn very easily

● I wear hearing aids

● Been to Italy and Greece

○ Hiked up Mt. Olympus

● Been to Iceland with this cool dude →

Page 7: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Presentation Outline

1. Overview

2. History

3. Applications

4. The Algorithm

5. Implementation and Results

6. Other Shortest Path Finding Algorithms

7. Open Issues

8. Summary

9. References

10. Discussion

Page 8: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Overview Slide

● Important Definitions

○ Path Finding Algorithms

■ DFS, BFS, Dijkstra’s, Bellman-Ford, etc.

○ Shortest Unweighted Path Finding Algorithm

■ BFS

○ Shortest Weighted Path Finding Algorithm

■ Dijkstra’s Algorithm, Bellman-Ford, etc.

● Applications

○ Google maps, network routing, etc.

Page 9: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Edsger Dijkstra

● Born on 1930 in Rotterdam, Netherlands

● Studied theoretical physics

● Held the Schlumberger Centennial Chair in Computer Sciences

at The University of Texas at Austin

● He retired in 2000

● Made a variety of algorithms

● Hates the GOTO statement

● Died in Nuenen, The Netherlands on August 6, 2002 after a long

struggle with cancer

Page 10: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Shortest Path Finding Algorithms: Beginnings

● 1950’s were when shortest path finding algorithms became the hot topic

● Shimble first proposed the idea in 1955

● However, Bellman and Ford both get credited with the algorithm because they published it in 1958

and 1956

○ Edward Moore also published it in 1957

○ Sometimes you will hear it called the Bellman-Ford-Moore algorithm

● In 1959 Dijkstra published his algorithm which was essentially a rediscovery of Prim's algorithm

○ Prim's algorithm was published 2 years earlier

■ Prim’s algorithm was a rediscovery of Jarník’s algorithm

Page 11: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Shortest Path Applications

● Popular shortest path finding application implementations:

○ Maps (Google, Apple, etc.)

○ Robot navigation

○ Typesetting in TeX

○ Urban traffic planning

○ Routing of telecommunications messages

○ Network routing protocols (OSPF, BGP, RIP)

○ Optimal truck routing through given traffic congestion pattern

○ Etc.

Page 12: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Real-Life Applications That Use Dijkstra’s

● Google Maps

● IP routing to find Open Shortest Path First

● The telephone network

Page 13: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Dijkstra’s Algorithm

● Canonical shortest, weighted pathfinding algorithm

● Runtime Complexity: O(E log(V))

● When to use?

○ One source → ALL Destinations

Dijkstra's Algorithm Animated, www3.cs.stonybrook.edu/~skiena/combinatorica/animations/dijkstra.html.

Page 14: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Algorithm - At a Glance

1. Create two sets one that has all of the nodes we have calculated the shortest distance to from our

source node (processed/closed) and a set for all other nodes (not_processed/open)

2. Initially, all nodes are in our not_processed set, and we set their distances from the source to infinity

3. While our processed set does not have all of the nodes (or the destination node)..

a. Pick a node u that is not in the processed set and has the minimum distance value and

include it in the processed set

b. Update distance value of all adjacent vertices of u

Page 15: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Algorithm - Example

0

1 2

3 4

5 6

Processed Not Processed

0: 0

1: ∞

2: ∞

3: ∞

4: ∞

5: ∞

6: ∞

4

8

7

5

3

1

6

9

Page 16: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Algorithm - Example

0

1 2

3 4

5 6

Processed Not Processed

0: 0 1: ∞

2: ∞

3: ∞

4: ∞

5: ∞

6: ∞

4

8

7

5

3

1

6

9

Page 17: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Algorithm - Example

0

1 2

3 4

5 6

Processed Not Processed

0: 0 1: 4

3: 8

2: ∞

4: ∞

5: ∞

6: ∞

4

8

7

5

3

1

6

9

Page 18: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Algorithm - Example

0

1 2

3 4

5 6

Processed Not Processed

0: 0 2: 7

1: 4 3: 8

5: 11

4: ∞

6: ∞

4

8

7

5

3

1

6

9

Page 19: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Algorithm - Example

0

1 2

3 4

5 6

Processed Not Processed

0: 0 3: 8

1: 4 5: 8

2: 7 4: ∞

6: ∞

4

8

7

5

3

1

6

9

Page 20: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Algorithm - Example

0

1 2

3 4

5 6

Processed Not Processed

0: 0 5: 8

1: 4 4: 13

2: 7 6: ∞

3: 8

4

8

7

5

3

1

6

9

Page 21: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Algorithm - Example

0

1 2

3 4

5 6

Processed Not Processed

0: 0 4: 13

1: 4 6: 17

2: 7

3: 8

5: 8

4

8

7

5

3

1

6

9

Page 22: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Algorithm - Example

0

1 2

3 4

5 6

Processed Not Processed

0: 0 6: 17

1: 4

2: 7

3: 8

5: 8

4: 13

4

8

7

5

3

1

6

9

Page 23: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Algorithm - Example

0

1 2

3 4

5 6

Processed Not Processed

0: 0

1: 4

2: 7

3: 8

5: 8

4: 13

6: 17

4

8

7

5

3

1

6

9

Page 24: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Implementation of Dijkstra’s

● Implemented in C++ using multimap to hold nodes in the open/unvisited set

● 2 type of graphs generated:

○ 3 connections per node

○ 7 connections per node

● Ran on graphs with nodes ranging from 1,000 to 100,000

○ Each run was performed 5 times and the average runtime is what’s reported

● All tests run on Macbook Pro 2.9 GHz 6-Core Intel Core i9

Page 25: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Implementation of Dijkstra’s

Nodes Closed Set Size Percentage

1,000 707 70.7%

10,000 6,623 66.2%

30,000 27,746 92.5%

50,000 24,112 48.2%

70,000 57,328 81.9%

90,000 58,289 64.8%

Nodes Closed Set Size Percentage

1,000 550 55.0%

10,000 7,451 74.5%

30,000 28,074 93.6%

50,000 22,086 44.2%

70,000 58,499 83.6%

90,000 57,526 63.9%

Page 26: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Implementation of Dijkstra’s

Page 27: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Other Shortest Pathfinding Algorithms

● A* Algorithm

● Bellman-Ford’s Algorithm

● Floyd-Warshall’s Algorithm

Page 28: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

A-Star (A*) SPF* Algorithm

● Dijkstra’s with a heuristic (h)

○ h is the “estimated movement cost to move from one node to the final destination”

● Calculating h can be exact or estimated with distances

○ Manhattan, Diagonal, and Euclidean distance metrics are popular estimations for h

● Runtime Complexity: O(E)

● When to use?

○ One Source → One Destination

Page 29: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Bellman-Ford’s SPF Algorithm

● Dijkstra’s algorithm doesn’t work for graphs with negative weight edges

○ But Bellman-Ford’s does

● For every node V, all edges are examined and an array of shortest distances to each node is built

● Runtime Complexity: O(VE)

● When to use?

○ One Source → ALL Destination Nodes

■ (When graph has negative weight edges)0

1 2

3 4

5 6

4

8

7

-1

-2

1

6

9

Page 30: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Floyd-Warshall’s SPF Algorithm

● “All Pairs Shortest Paths”

● Works on a matrix of size i * j

● Runtime Complexity: O(V3)

● When to use?

○ Calculating shortest distances between EVERY pair of nodes

Page 31: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Summary

● Dijkstra’s algorithm is very popular SPF algorithm

● Best use case is from one source to all destination nodes

Algorithm Runtime Complexities

A* O(E)

Dijkstra’s O(E log (V))

Bellman-Ford’s O(VE)

Floyd-Warshall’s O(V3)

Page 32: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Open Issues

● One of the problems with using Dijkstra’s algorithm on the Internet is that you must have a

complete representation of the graph in order for the algorithm to run.

Page 33: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

References

1. “8.20. Dijkstra's Algorithm¶.” 8.20. Dijkstra's Algorithm - Problem Solving with Algorithms and Data Structures, runestone.academy/runestone/books/published/pythonds/Graphs/DijkstrasAlgorithm.html.

2. “A* Search Algorithm.” GeeksforGeeks, 7 Sept. 2018, www.geeksforgeeks.org/a-search-algorithm/.

3. “Bellman–Ford Algorithm.” Wikipedia, Wikimedia Foundation, 10 Mar. 2020, en.wikipedia.org/wiki/Bellman–Ford_algorithm.

4. “Bellman–Ford Algorithm: DP-23.” GeeksforGeeks, 7 Aug. 2019, www.geeksforgeeks.org/bellman-ford-algorithm-dp-23/.

5. “Biography.” IEEE Computer Society Edsger Dijkstra Comments, www.computer.org/profiles/edsger-dijkstra.

6. “Dijkstra's Algorithm.” Wikipedia, Wikimedia Foundation, 14 Mar. 2020, en.wikipedia.org/wiki/Dijkstra's_algorithm.

7. Dijkstra's Algorithm Animated, www3.cs.stonybrook.edu/~skiena/combinatorica/animations/dijkstra.html.

8. “Dijsktra's Algorithm.” GeeksforGeeks, 4 Sept. 2019, www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-greedy-algo-7/.

9. “Floyd Warshall Algorithm: DP-16.” GeeksforGeeks, 18 July 2019, www.geeksforgeeks.org/floyd-warshall-algorithm-dp-16/.

10. “Overview.” Graph Theory: Networking, www.ibiblio.org/links/devmodules/graph_networking/compat/page23.html.

11. Plank, James. CS302 Lecture Notes, web.eecs.utk.edu/~jplank/plank/classes/cs302/Notes/BFS/.

12. Plank, James. CS494 Lecture Notes, web.eecs.utk.edu/~jplank/plank/classes/cs494/494/notes/A-Star/.

13. Sedgewick, Robert and Wayne, Kevin. 4.4 Shortest Paths. cs.princeton.edu/courses/archive/spr10/cos226/lectures/15-44ShortestPaths-2x2.pdf.

14. “Shortest Path Algorithms Tutorials & Notes: Algorithms.” HackerEarth, www.hackerearth.com/practice/algorithms/graphs/shortest-path-algorithms/tutorial/.

15. “The Centre for Computing History.” Centre For Computing History, www.computinghistory.org.uk/det/4179/Edsger-Dijkstra/.

Page 34: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Discussion Slide

● How’d you guys like Zoom for a presentation like this?

● Are you thinking about all the cool things you could be doing with Dijkstra’s algorithm now?

● Do you think it’s fair to have an algorithm named after you if it’s more or less a rediscovery of an

earlier algorithm?

Page 35: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

Test Questions

1. What is the run time complexity of Dijkstra’s algorithm?

2. What case is Dijkstra’s algorithm best used for?

3. What was the Dijkstra’s algorithm a rediscovery of?

Page 36: Dijkstra’s Algorithmweb.eecs.utk.edu/~roffutt/files/sp20ppts/Cool Man...Dijkstra’s Algorithm, Bellman-Ford, etc. Applications Google maps, network routing, etc. Edsger Dijkstra

The End

Thanks for zooming in :)