lecture 37 - university at buffaloatri/cse331/fall18/lectures/lect37.pdf · lecture 37 cse 331 dec...

12
Lecture 37 CSE 331 Dec 3, 2018

Upload: others

Post on 15-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 37 - University at Buffaloatri/cse331/fall18/lectures/lect37.pdf · Lecture 37 CSE 331 Dec 3, 2018. Quiz 2 1:00-1:10pm Lecture starts at 1:15pm. Final Reminder. Noquizdiscussiononpiazza

Lecture 37

CSE 331Dec 3, 2018

Page 2: Lecture 37 - University at Buffaloatri/cse331/fall18/lectures/lect37.pdf · Lecture 37 CSE 331 Dec 3, 2018. Quiz 2 1:00-1:10pm Lecture starts at 1:15pm. Final Reminder. Noquizdiscussiononpiazza

Quiz 2

1:00-1:10pm

Lecture starts at 1:15pm

Page 3: Lecture 37 - University at Buffaloatri/cse331/fall18/lectures/lect37.pdf · Lecture 37 CSE 331 Dec 3, 2018. Quiz 2 1:00-1:10pm Lecture starts at 1:15pm. Final Reminder. Noquizdiscussiononpiazza

Final Reminder

Page 4: Lecture 37 - University at Buffaloatri/cse331/fall18/lectures/lect37.pdf · Lecture 37 CSE 331 Dec 3, 2018. Quiz 2 1:00-1:10pm Lecture starts at 1:15pm. Final Reminder. Noquizdiscussiononpiazza

No quiz discussion on piazza

till Noon

Page 5: Lecture 37 - University at Buffaloatri/cse331/fall18/lectures/lect37.pdf · Lecture 37 CSE 331 Dec 3, 2018. Quiz 2 1:00-1:10pm Lecture starts at 1:15pm. Final Reminder. Noquizdiscussiononpiazza

Review sessions/extra OHFriday lecture will be a Q&A session

Page 6: Lecture 37 - University at Buffaloatri/cse331/fall18/lectures/lect37.pdf · Lecture 37 CSE 331 Dec 3, 2018. Quiz 2 1:00-1:10pm Lecture starts at 1:15pm. Final Reminder. Noquizdiscussiononpiazza

HWs 6-9 solutions

At the end of the lecture

Page 7: Lecture 37 - University at Buffaloatri/cse331/fall18/lectures/lect37.pdf · Lecture 37 CSE 331 Dec 3, 2018. Quiz 2 1:00-1:10pm Lecture starts at 1:15pm. Final Reminder. Noquizdiscussiononpiazza

Shortest Path Problem

Input: (Directed) Graph G=(V,E) and for every edge e has a cost ce (can be <0)

t in V

Output: Shortest path from every s to t

1 1

100

-1000

899

s t

Shortest path has cost negative

infinity

Assume that Ghas no negative

cycle

Page 8: Lecture 37 - University at Buffaloatri/cse331/fall18/lectures/lect37.pdf · Lecture 37 CSE 331 Dec 3, 2018. Quiz 2 1:00-1:10pm Lecture starts at 1:15pm. Final Reminder. Noquizdiscussiononpiazza

When to use Dynamic Programming

There are polynomially many sub-problems

Optimal solution can be computed from solutions to sub-problems

There is an ordering among sub-problem that allows for iterative solution

Richard Bellman

Page 9: Lecture 37 - University at Buffaloatri/cse331/fall18/lectures/lect37.pdf · Lecture 37 CSE 331 Dec 3, 2018. Quiz 2 1:00-1:10pm Lecture starts at 1:15pm. Final Reminder. Noquizdiscussiononpiazza

Sub-problems

OPT(u,i) = cost of shortest path from u to t with at most i edges

Page 10: Lecture 37 - University at Buffaloatri/cse331/fall18/lectures/lect37.pdf · Lecture 37 CSE 331 Dec 3, 2018. Quiz 2 1:00-1:10pm Lecture starts at 1:15pm. Final Reminder. Noquizdiscussiononpiazza

Today’s agenda

Finish Bellman-Ford algorithm

Analyze the run time

Page 11: Lecture 37 - University at Buffaloatri/cse331/fall18/lectures/lect37.pdf · Lecture 37 CSE 331 Dec 3, 2018. Quiz 2 1:00-1:10pm Lecture starts at 1:15pm. Final Reminder. Noquizdiscussiononpiazza

The recurrence

OPT(u,i) = shortest path from u to t with at most i edges

OPT(u,i) = min { OPT(u,i-1), min(u,w) in E { cu,w + OPT(w, i-1)} }

Page 12: Lecture 37 - University at Buffaloatri/cse331/fall18/lectures/lect37.pdf · Lecture 37 CSE 331 Dec 3, 2018. Quiz 2 1:00-1:10pm Lecture starts at 1:15pm. Final Reminder. Noquizdiscussiononpiazza

Some consequencesOPT(u,i) = cost of shortest path from u to t with at most i edges

OPT(u,i) = min { OPT(u, i-1), min(u,w) in E { cu,w + OPT(w,i-1)} }

OPT(u,n-1) is shortest path cost between u and t

Group talk time:How to compute the shortest path between s and t given all

OPT(u,i) values