1 / 41

Lecture on Shortest Path Problem Quiz

This quiz sample tests your knowledge on dynamic programming and topological sorting algorithms for the shortest path problem. It also discusses the running time and smart implementation of these algorithms.

johnchapman
Download Presentation

Lecture on Shortest Path Problem Quiz

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. Lecture 6 Shortest Path Problem

  2. Quiz Sample • True or False • Every dynamic programming can be analyzed with formula: • Run-time = (table size) • x (computation time of recursive formula). • Answer: False • A counterexample can be seen in study of the shortest path problem.

  3. s t

  4. Dynamic Programming

  5. Dynamic Programming

  6. Dynamic Programming

  7. Lemma Proof

  8. Theorem 2 -1 -1 1 2

  9. Counterexample

  10. Quiz Sample • True or false? • Every algorithm of dynamic-programming type can use the following formula to estimate its running time: • running time = (table size) x (computing time • for recursive formula).

  11. Running Time Is above calculation correct?

  12. Running Time Is above calculation correct?

  13. Smart Implementation

  14. Running Time how much time do we need?

  15. Running Time how much time do we need? A topological ordering is an ordering of nodes such that for any edge (u,v), u is put before v.

  16. Topological Sort (Kahn)

  17. 1 An Example 4 2 4 2 2 2 1 3 1 6 4 2 3 3 5

  18. 1 An Example 4 2 4 2 2 1 3 1 6 2 3 3 5

  19. 1 An Example 4 2 4 2 2 1 3 1 6 2 3 3 5

  20. 1 An Example 2 4 2 3 1 6 2 3 3 5

  21. 1 An Example 2 4 2 3 1 6 2 3 3 5

  22. 1 An Example 2 4 2 3 1 6 2 3 5

  23. 1 An Example 2 4 2 3 1 6 2 3 5

  24. 1 An Example 2 4 2 1 6 3 5

  25. 1 An Example 2 4 2 3 1 6 2 3 5

  26. Topological Sort (Kahn)

  27. Smart Implementation

  28. Theorem • Dynamic Programming is a linear time algorithm for the shortest path problem in acyclic networks, possibly with negative weight. • total running time O(m+n).

  29. 1 An Example   4 2 4 2 2 0 2 1 3  1 6 4 2 3 3 5   Initialize Select the node with the minimum temporary distance label.

  30. Update Step 2   4 2 4 2 2 0 2 1 3  1 6 4 2 3 3 5   4

  31. Choose u such that D(u)=Ǿ 2  4 2 4 2 2 0 2 1 3  1 6 4 2 3 3 5  4

  32. Update Step 6 2  4 2 4 2 2 0 2 1 3  1 6 4 2 3 3 5  4 4 3 The predecessor of node 3 is now node 2

  33. Choose u Such That N_(u) S 2 6 4 2 4 2 2 0 2 1 3  1 6 4 2 3 3 5 3 4

  34. Update 2 6 4 2 4 2 2 0 2 1 3  1 6 4 2 3 3 5 3 4 d(5) is not changed.

  35. Choose u s.t . N_(u) S 2 6 4 2 4 2 2 0 2 1 3  1 6 4 2 3 3 5 3 4

  36. Update 2 6 4 2 4 2 2 0 6 2 1 3  1 6 4 2 3 3 5 3 4 d(4) is not changed

  37. Choose u s.t. N_(u) S 2 6 4 2 4 2 2 0 2 1 3 6 1 6 4 2 3 3 5 3 4

  38. Update 2 6 4 2 4 2 2 0 2 1 3 6 1 6 4 2 3 3 5 3 4 d(6) is not updated

  39. Choose u s.t. N_(u) S 2 6 4 2 4 2 2 0 2 1 3 6 1 6 4 2 3 3 5 3 4 There is nothing to update

  40. End of Algorithm 2 6 4 2 4 2 2 0 2 1 3 6 1 6 4 2 3 3 5 3 4 All nodes are now permanent The predecessors form a tree The shortest path from node 1 to node 6 can be found by tracing back predecessors

  41. Theorem • Dynamic Programming is a linear time algorithm for the shortest path problem in acyclic networks, possibly with negative weight. • Corollary. In acyclic networks, the longest path can be computed in linear time. (QE 2015F) Why?

More Related