![Page 1: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/1.jpg)
Lecture33
CSE331Nov17,2017
![Page 2: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/2.jpg)
Homework9
![Page 3: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/3.jpg)
Thanksgivingbreak
![Page 4: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/4.jpg)
HW8solutions
End of the lecture
![Page 5: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/5.jpg)
GradedHW6
Done by today
Apologies for the delay!
![Page 6: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/6.jpg)
CSEdweek(Dec8)
![Page 7: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/7.jpg)
SEASSeniorScholarProgram
![Page 8: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/8.jpg)
AskQsplease!
![Page 9: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/9.jpg)
WeightedIntervalScheduling
Input:n jobs(si,fi,vi)
Output:AscheduleS s.t.notwojobsinS haveaconflict
Goal:maxΣiinSvj
Assume:jobsaresortedbytheirfinishtime
![Page 10: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/10.jpg)
Couplemoredefinitions
p(j)=largesti<j s.t.i doesnotconflictwithj
=0 ifnosuch iexists
OPT(j)=optimalvalueoninstance1,..,j
p(j)<j
![Page 11: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/11.jpg)
PropertyofOPT
OPT(j)=max{ vj +OPT(p(j)),OPT(j-1) }
j inOPT(j)j notinOPT(j)
GivenOPT(1),….,OPT(j-1),howcanonefigureoutifjinoptimalsolutionornot?
![Page 12: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/12.jpg)
![Page 13: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/13.jpg)
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)
![Page 14: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/14.jpg)
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!
![Page 15: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/15.jpg)
![Page 16: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/16.jpg)
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
![Page 17: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/17.jpg)
HowmanydistinctOPTvalues?
![Page 18: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/18.jpg)
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)
![Page 19: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/19.jpg)
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
![Page 20: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/20.jpg)
![Page 21: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/21.jpg)
PropertyofOPT
OPT(j)=max{ vj +OPT(p(j)),OPT(j-1) }
GivenOPT(1),…,OPT(j-1),onecancomputeOPT(j)
![Page 22: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/22.jpg)
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
![Page 23: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/23.jpg)
![Page 24: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/24.jpg)
ReadingAssignmentSec6.1,6.2of[KT]
![Page 25: Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33 CSE 331 Nov 17, 2017. Homework 9. Thanksgiving break. HW 8 solutions End of the](https://reader034.vdocuments.site/reader034/viewer/2022051606/602aa2421bfa824a697fdc0c/html5/thumbnails/25.jpg)
WhentouseDynamicProgramming
Therearepolynomiallymanysub-problems
Optimalsolutioncanbecomputedfromsolutionstosub-problems
Thereisanorderingamongsub-problemthatallowsforiterativesolution
RichardBellman