SLIDE 1 Dynamic programming
Topics for this week:
- backtracking revisited: a brute-force technique that finds a
solution by trying all possibilities (usually VERY SLOW)
- sometimes can be remedied by storing pre-computed values:
called dynamic programming
- comparing the time complexities: dyn-prog is usually very
fast
[Week 9]
SLIDE 2
Problem: Job Scheduling with Pay
You are a tile installer who has many jobs to choose from. Every job has a start time, finish time, and the pay you get for doing the job. You want to take those non-overlapping jobs that maximize your pay. Example: repairing old tiles, 8-10am, $200 grout sealing, 11-11:30am, $50 installing new tiles, 9am-12pm, $400
SLIDE 3 Problem: Job Scheduling with Pay
Greedy approaches:
- Do the greedy strategies from last quarter work ?
- What about a strategy that takes the most expensive job
first, removes overlapping jobs, and continues with the same approach ?
SLIDE 4
Problem: Job Scheduling with Pay
Backtracking through all possible sets of non-overlapping jobs. [This is also called exhaustive enumeration.] Pseudo code:
SLIDE 5
Problem: Job Scheduling with Pay
A stack-frame diagram of the enumeration pseudo code: Time complexity:
SLIDE 6
Problem: Job Scheduling with Pay
A dynamic programming approach: Time complexity:
SLIDE 7
Problem: Job Scheduling with Pay
Tracing a more interesting example: Testing: