Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33...

25
Lecture 33 CSE 331 Nov 17, 2017

Transcript of Lecture 33 - UB CSE Development Web Server Tutorialatri/cse331/fall17/lectures/lect33.pdfLecture 33...

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

WhentouseDynamicProgramming

Therearepolynomiallymanysub-problems

Optimalsolutioncanbecomputedfromsolutionstosub-problems

Thereisanorderingamongsub-problemthatallowsforiterativesolution

RichardBellman