Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 6 Shortest Path Problem.

Similar presentations


Presentation on theme: "Lecture 6 Shortest Path Problem."— 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 An Example 4 2 4 2 2 1 2 3 1 1 6 4 2 3 3 5

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

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

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

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

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

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

24 An Example 2 4 2 1 1 6 3 5

25 An Example 2 4 2 3 1 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 An Example      Initialize
4 2 4 2 2 1 2 3 1 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 1 2 3 1 6 4 2 3 3 5 4

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

32 Update Step 6 2    4 4 3 The predecessor of node 3 is now node 2 4
1 2 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 1 2 3 1 6 4 2 3 3 5 3 4

34 Update 2 6 4 2 4 2 2 1 2 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 1 2 3 1 6 4 2 3 3 5 3 4

36 Update 2 6 4 2 4 2 2 6 1 2 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 1 2 3 6 1 6 4 2 3 3 5 3 4

38 Update 2 6 4 2 4 2 2 1 2 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 6 3 4 There is nothing to update 4 2 4 2 2 1
1 2 3 6 1 6 4 2 3 3 5 3 4 There is nothing to update

40 End of Algorithm 2 6 6 3 4 All nodes are now permanent
1 2 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?


Download ppt "Lecture 6 Shortest Path Problem."

Similar presentations


Ads by Google