[Week 9] 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
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
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 ?
Problem: Job Scheduling with Pay Backtracking through all possible sets of non-overlapping jobs. [This is also called exhaustive enumeration.] Pseudo code:
Problem: Job Scheduling with Pay A stack-frame diagram of the enumeration pseudo code: Time complexity:
Problem: Job Scheduling with Pay A dynamic programming approach: Time complexity:
Problem: Job Scheduling with Pay Tracing a more interesting example: Testing:
Recommend
More recommend