Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 36 CSE 331 Nov 30, 2012.

Similar presentations


Presentation on theme: "Lecture 36 CSE 331 Nov 30, 2012."— Presentation transcript:

1 Lecture 36 CSE 331 Nov 30, 2012

2 HW 9 due today I will not take any HW after 1:15pm
Q1, Q 2 and Q 3 in separate piles I will not take any HW after 1:15pm

3 Other HW related stuff Solutions to HW 9 at the end of the lecture
HW 8 should be available for pickup from Monday HW 10 has been posted on the blog (Due in last lecture)

4 Sample final exam Posted on blog/piazza Final exam from last year
Can submit Q1 and Q2 as Q4 on HW 10 next Friday

5 Weighted Interval Scheduling
Input: n jobs (si,ti,vi) Output: A schedule S s.t. no two jobs in S have a conflict Goal: max Σi in S vj Assume: jobs are sorted by their finish time

6 Couple more definitions
p(j) = largest i<j s.t. i does not conflict with j p(j) < j = 0 if no such i exists OPT(j) = optimal value on instance 1,..,j

7 HW 9 due today I will not take any HW after 1:15pm
Q1, Q 2 and Q 3 in separate piles I will not take any HW after 1:15pm

8 Property of OPT OPT(j) = max { vj + OPT( p(j) ), OPT(j-1) }
j not in OPT(j) j in OPT(j) OPT(j) = max { vj + OPT( p(j) ), OPT(j-1) } Given OPT(1),…., OPT(j-1), how can one figure out if j in optimal solution or not?

9

10 Proof of correctness by induction on j
A recursive algorithm Proof of correctness by induction on j Correct for j=0 Compute-Opt(j) If j = 0 then return 0 return max { vj + Compute-Opt( p(j) ), Compute-Opt( j-1 ) } = OPT( p(j) ) = OPT( j-1 ) OPT(j) = max { vj + OPT( p(j) ), OPT(j-1) }

11 Exponential Running Time
1 2 3 4 5 p(j) = j-2 Only 5 OPT values! OPT(5) OPT(3) OPT(4) Formal proof: Ex. OPT(2) OPT(3) OPT(1) OPT(2) OPT(1) OPT(2) OPT(1)

12

13 How many distinct OPT values?

14 A recursive algorithm M-Compute-Opt(j) = OPT(j) M-Compute-Opt(j)
If j = 0 then return 0 If M[j] is not null then return M[j] M[j] = max { vj + M-Compute-Opt( p(j) ), M-Compute-Opt( j-1 ) } return M[j] Run time = O(# recursive calls)

15 Bounding # recursions M-Compute-Opt(j) If j = 0 then return 0
O(n) overall If j = 0 then return 0 If M[j] is not null then return M[j] M[j] = max { vj + M-Compute-Opt( p(j) ), M-Compute-Opt( j-1 ) } return M[j] Whenever a recursive call is made an M value of assigned At most n values of M can be assigned

16

17 Property of OPT Given OPT(1), …, OPT(j-1), one can compute OPT(j)
OPT(j) = max { vj + OPT( p(j) ), OPT(j-1) } Given OPT(1), …, OPT(j-1), one can compute OPT(j)

18 Recursion+ memory = Iteration
Iteratively compute the OPT(j) values Iterative-Compute-Opt M[0] = 0 M[j] = max { vj + M[p(j)], M[j-1] } For j=1,…,n M[j] = OPT(j) O(n) run time

19

20 Reading Assignment Sec 6.1, 6.2 of [KT]

21 When to use Dynamic Programming
There are polynomially many sub-problems Richard Bellman Optimal solution can be computed from solutions to sub-problems There is an ordering among sub-problem that allows for iterative solution

22 Shortest Path Problem Input: (Directed) Graph G=(V,E) and for every edge e has a cost ce (can be <0) t in V Output: Shortest path from every s to t Assume that G has no negative cycle 1 100 -1000 899 s t Shortest path has cost negative infinity

23 Rest of today’s agenda Dynamic Program for shortest path

24 May the Bellman force be with you


Download ppt "Lecture 36 CSE 331 Nov 30, 2012."

Similar presentations


Ads by Google