1 / 138

Graphs: MSTs and Shortest Paths

Graphs: MSTs and Shortest Paths. David Kauchak cs161 Summer 2009. Administrative. Grading final grade extra credit TA issues/concerns HW6 shorter will be due Wed. 8/12 before class Errors in class slides and notes Anonymized scores posted. A. B. C. E. D. Shortest paths.

franz
Download Presentation

Graphs: MSTs and Shortest Paths

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Graphs: MSTsand Shortest Paths David Kauchak cs161 Summer 2009

  2. Administrative • Grading • final grade • extra credit • TA issues/concerns • HW6 • shorter • will be due Wed. 8/12 before class • Errors in class slides and notes • Anonymized scores posted

  3. A B C E D Shortest paths • What is the shortest path from a to d?

  4. A B C E D Shortest paths • BFS

  5. A B C E D Shortest paths • What is the shortest path from a to d? 2 3 3 2 1 1 4

  6. A B C E D Shortest paths • We can still use BFS 2 3 3 2 1 1 4

  7. D A B D E E B A C C Shortest paths • We can still use BFS 2 3 3 2 1 1 4

  8. A B C E D Shortest paths • We can still use BFS

  9. A B C E D Shortest paths • What is the problem?

  10. A B C A B C Shortest paths • Running time is dependent on the weights 100 2 50 1 200 4

  11. A B C A B C Shortest paths 100 50 200

  12. A B C Shortest paths

  13. A B C Shortest paths

  14. A B C Shortest paths • Nothing will change as we expand the frontier until we’ve gone out 100 levels

  15. Dijkstra’s algorithm

  16. Dijkstra’s algorithm

  17. Dijkstra’s algorithm prev keeps track of the shortest path

  18. Dijkstra’s algorithm

  19. Dijkstra’s algorithm

  20. Dijkstra’s algorithm

  21. Single source shortest paths • All of the shortest path algorithms we’ll look at today are call “single source shortest paths” algorithms • Why?

  22. A B C E D 3 3 1 2 1 1 4

  23. A B C E D   3 3  1 2 1  1  4

  24. A B C E D Heap A 0B CDE   3 3 0 1 2 1  1  4

  25. A B C E D Heap B CDE   3 3 0 1 2 1  1  4

  26. A B C E D Heap B CDE   3 3 0 1 2 1  1  4

  27. A B C E D Heap C 1B DE   3 3 0 1 2 1 1 1  4

  28. A B C E D Heap C 1B DE   3 3 0 1 2 1 1 1  4

  29. A B C E D Heap C 1B 3DE 3  3 3 0 1 2 1 1 1  4

  30. A B C E D Heap C 1B3DE 3  3 3 0 1 2 1 1 1  4

  31. A B C E D Heap B3DE 3  3 3 0 1 2 1 1 1  4

  32. A B C E D Heap B3DE 3  3 3 0 1 2 1 1 1  4

  33. A B C E D Heap B3DE 3  3 3 0 1 2 1 1 1  4

  34. A B C E D Heap B2DE 2  3 3 0 1 2 1 1 1  4

  35. A B C E D Heap B2DE 2  3 3 0 1 2 1 1 1  4

  36. A B C E D Heap B2E 5D 2  3 3 0 1 2 1 1 1 5 4

  37. A B C E D Heap B2E 5D 2  3 3 0 1 Frontier? 2 1 1 1 5 4

  38. A B C E D Heap B2E 5D 2  3 3 0 All nodes reachable from starting node within a given distance 1 2 1 1 1 5 4

  39. A B C E D Heap E3D 5 2 5 3 3 0 1 2 1 1 1 3 4

  40. A B C E D Heap D 5 2 5 3 3 0 1 2 1 1 1 3 4

  41. A B C E D Heap 2 5 3 3 0 1 2 1 1 1 3 4

  42. A B C E D Heap 2 5 3 0 1 1 1 1 3

  43. Is Dijkstra’s algorithm correct? • Invariant:

  44. Is Dijkstra’s algorithm correct? • Invariant: For every vertex removed from the heap, dist[v] is the actual shortest distance from s to v

  45. Is Dijkstra’s algorithm correct? • Invariant: For every vertex removed from the heap, dist[v] is the actual shortest distance from s to v • The only time a vertex gets visited is when the distance from s to that vertex is smaller than the distance to any remaining vertex • Therefore, there cannot be any other path that hasn’t been visited already that would result in a shorter path

  46. Running time?

  47. Running time? 1 call to MakeHeap

  48. Running time? |V| iterations

  49. Running time? |V| calls

  50. Running time? O(|E|) calls

More Related