Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 32 CSE 331 Nov 16, 2016.

Similar presentations


Presentation on theme: "Lecture 32 CSE 331 Nov 16, 2016."— Presentation transcript:

1 Lecture 32 CSE 331 Nov 16, 2016

2 Talk today

3 Three general techniques
High level view of CSE 331 Problem Statement Problem Definition Three general techniques Algorithm “Implementation” Data Structures Analysis Correctness+Runtime Analysis

4 Greedy Algorithms Natural algorithms
Reduced exponential running time to polynomial

5 Divide and Conquer Recursive algorithmic paradigm
Reduced large polynomial time to smaller polynomial time

6 A new algorithmic technique
Dynamic Programming

7 Dynamic programming vs. Divide & Conquer

8 Same same because Both design recursive algorithms

9 Different because Dynamic programming is smarter about solving recursive sub-problems

10 End of Semester blues Can only do one thing at any day: what is the optimal schedule to obtain maximum value? Write up a term paper (30) (3) (2) (5) (10) Party! Exam study 331 HW Project Monday Tuesday Wednesday Thursday Friday

11 Previous Greedy algorithm
Order by end time and pick jobs greedily Greedy value = 5+2+3= 10 Write up a term paper (10) OPT = 30 Party! (2) Exam study (5) 331 HW (3) Project (30) Monday Tuesday Wednesday Thursday Friday

12 Today’s agenda Formal definition of the problem
Start designing a recursive algorithm for the problem

13 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?

14

15 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) }

16 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)

17

18 How many distinct OPT values?

19 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)

20 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

21

22 Reading Assignment Sec 6.1, 6.2 of [KT]

23 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


Download ppt "Lecture 32 CSE 331 Nov 16, 2016."

Similar presentations


Ads by Google