CS252 Algorithms Wednesday, 17 April 2024 + Questions + What's next? algorithmic paradigms - greedy algorithms (weeks 4 & 5) - shortest paths - minimum spanning trees - divide-and-conquer algorithms (week 6) - dynamic programming (weeks 7-8) - network flows (week 9) + Greedy algorithms - Greedy is an adjective - K&T Ch 4: "It is hard, if not impossible, to define precisely what is meant by a greedy algorithm. An algorithm is greedy if it builds up a solution in small steps, choosing a decision at each step myopically to optimize some underlying criterion." + Interval scheduling - The problem In? Request to use the shared resource R = {[start_time_1, finish_time_1], [s2,f2]... } Out? A = subset of R = {...} non-overlapping elements of R with the maximal size (# of requests) (notably, what are we optimizing here?) size of A Why are we looking at this problem? - a greedy approach works - it's satisfying (elegant, simple alg., and it works! the proof is nice) - several obvious greedy approaches fail - Greedy options - :) grab an interval from R that works with A (no overlaps) and has the earliest finish time - :( grab an interval that starts as soon as possible - :( grab the smallest interval - Counter-examples - Our algorithm - Correctness proof - "staying ahead of optimal" - Implementation and runtime + Related problems - Maximize total length of intervals in A - Maximize weights - Minimize maximum lateness (start times are min start times) - Minimize total lateness - All of those, but with multiple copies of the resource - ... + Exchange argument - Problem: interval scheduling to minimize max lateness