next up previous
Next: Activity Selection Problem Up: CSE 2320: Algorithms and Previous: Fractional Knapsack Problem

Activity-Selection (scheduling) problem

Problem: Select maximum-size set of compatible activities. Assume the input is sorted by \(f_1 \leq f_2 \leq .. \leq f_n\) (O(nlgn)).

Greedy algorithm:

Greedy-AS(s, f)
1
$\;\;\;\;\;$n = length(s)
2
$\;\;\;\;\;$A = {1} $\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$; Initialize A
3
$\;\;\;\;\;$j = 1
4
$\;\;\;\;\;$for i = 2 to n
5
$\;\;\;\;\;$ $\;\;\;\;\;$if $s_i \geq f_j$ $\;\;\;\;\;$ $\;\;\;\;\;$; Compatible
6
$\;\;\;\;\;$ $\;\;\;\;\;$then A = A $\cup$ {i}
7
$\;\;\;\;\;$ $\;\;\;\;\;$ $\;\;\;\;\;$j = i
8
$\;\;\;\;\;$return A



\psfig{figure=figures/f9-4.ps}



Copyright © 1998 The University of Texas at Arlington