Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 33 CSE 331 Nov 14, 2014.

Similar presentations


Presentation on theme: "Lecture 33 CSE 331 Nov 14, 2014."— Presentation transcript:

1 Lecture 33 CSE 331 Nov 14, 2014

2 HW 8 due today Place Q1, Q2 and Q3 in separate piles
I will not accept HWs after 1:15pm DO NOT FORGET TO WRITE DOWN YOUR SOURCES

3 Related HW stuff HW 9 has been posted on piazza
Solutions to HW 8 at the END of the lecture Can pick up graded HW 7 from Monday

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

5 Greedy Algorithms Natural algorithms
Reduced exponential running time to polynomial

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

7 A new algorithmic technique
Dynamic Programming

8 Dynamic programming vs. Divide & Conquer

9 Same same because Both design recursive algorithms

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

11 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

12 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

13 HW 8 due today Place Q1, Q2 and Q3 in separate piles
I will not accept HWs after 1:15pm DO NOT FORGET TO WRITE DOWN YOUR SOURCES

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

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

16

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

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

19

20 How many distinct OPT values?

21 Using Memory to be smarter
Pow (a,n) // n is even and ≥ 2 return t * t t= Pow(a,n/2) Pow (a,n) // n is even and ≥ 2 return Pow(a,n/2) * Pow(a, n/2) O(n) as we recompute! O(log n) as we compute only once

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

23 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

24

25 Reading Assignment Sec 6.1, 6.2 of [KT]

26 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 33 CSE 331 Nov 14, 2014."

Similar presentations


Ads by Google