02-greedy

Select a first item 2 eliminate items that are

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Pick the next compatible one that starts earliest Pick the shortest one Pick the one that has the least conflicts (i.e. overlaps) 53 Activity­Selection Formally: Given a set S of n activities si = start time of activity I fi = finish time of activity i Find max-size subset A of compatible activities 3 4 6 2 1 54 5 Assume (wlog) that f1 f2 … fn Activity Selection: A Greedy Algorithm So actual algorithm is simple: Schedule the first activity Then schedule the next activity in sorted list which starts after previous activity finishes Sort the activities by finish time Repeat until no more activities Intuition is even more simple: 55 Always pick next activity that finishes earliest Activity Selection: Optimal Substructure Let k be the minimum activity in A (i.e., the one with the earliest finish time). Then A - {k} is an optimal solution to S’ = {i S: si fk} In words: once activity #1 is selected, the problem reduces to finding an optimal solution for activity-selection over activities in S compatible with #1 Proof: if we could find optimal solution B’ to S’ wit...
View Full Document

This note was uploaded on 02/25/2014 for the course CS 4102 taught by Professor Horton during the Spring '10 term at UVA.

Ask a homework question - tutors are online