View
3
Download
0
Category
Preview:
Citation preview
Lecture33
CSE331Nov17,2017
Homework9
Thanksgivingbreak
HW8solutions
End of the lecture
GradedHW6
Done by today
Apologies for the delay!
CSEdweek(Dec8)
SEASSeniorScholarProgram
AskQsplease!
WeightedIntervalScheduling
Input:n jobs(si,fi,vi)
Output:AscheduleS s.t.notwojobsinS haveaconflict
Goal:maxΣiinSvj
Assume:jobsaresortedbytheirfinishtime
Couplemoredefinitions
p(j)=largesti<j s.t.i doesnotconflictwithj
=0 ifnosuch iexists
OPT(j)=optimalvalueoninstance1,..,j
p(j)<j
PropertyofOPT
OPT(j)=max{ vj +OPT(p(j)),OPT(j-1) }
j inOPT(j)j notinOPT(j)
GivenOPT(1),….,OPT(j-1),howcanonefigureoutifjinoptimalsolutionornot?
Arecursivealgorithm
Compute-Opt(j)
Ifj=0thenreturn0
returnmax{ vj +Compute-Opt(p(j) ),Compute-Opt(j-1 )}
OPT(j)=max{ vj +OPT(p(j)),OPT(j-1) }
ProofofcorrectnessbyinductiononjCorrectforj=0
=OPT(p(j)) =OPT(j-1)
ExponentialRunningTime1
23
45
p(j)=j-2
OPT(5)
OPT(3) OPT(4)
OPT(1) OPT(2)
OPT(1) OPT(1)
OPT(1)OPT(2)
OPT(1)
OPT(2)
OPT(3)Formal
proof:Ex.
Only5OPTvalues!
UsingMemorytobesmarter
Pow (a,n)
// n is even and ≥ 2
return Pow(a,n/2) * Pow(a, n/2)
O(n)aswerecompute!
Pow (a,n)
// n is even and ≥ 2
return t * tt= Pow(a,n/2)
O(log n)aswecomputeonlyonce
HowmanydistinctOPTvalues?
Arecursivealgorithm
M-Compute-Opt(j)
Ifj=0thenreturn0
M[j]=max{ vj +M-Compute-Opt(p(j) ),M-Compute-Opt(j-1 )}
IfM[j]isnotnullthenreturnM[j]
returnM[j]
M-Compute-Opt(j)=OPT(j)
Runtime=O(#recursivecalls)
Bounding#recursionsM-Compute-Opt(j)
Ifj=0thenreturn0
M[j]=max{ vj +M-Compute-Opt(p(j) ),M-Compute-Opt(j-1 )}
IfM[j]isnotnullthenreturnM[j]
returnM[j]
WheneverarecursivecallismadeanM valueisassigned
Atmostn valuesofM canbeassigned
O(n)overall
PropertyofOPT
OPT(j)=max{ vj +OPT(p(j)),OPT(j-1) }
GivenOPT(1),…,OPT(j-1),onecancomputeOPT(j)
Recursion+memory=IterationIterativelycomputetheOPT(j)values
M[0]=0
M[j]=max{ vj +M[p(j)],M[j-1]}
Forj=1,…,n
Iterative-Compute-Opt
M[j]=OPT(j) O(n)runtime
ReadingAssignmentSec6.1,6.2of[KT]
WhentouseDynamicProgramming
Therearepolynomiallymanysub-problems
Optimalsolutioncanbecomputedfromsolutionstosub-problems
Thereisanorderingamongsub-problemthatallowsforiterativesolution
RichardBellman
Recommended