Professional Documents
Culture Documents
Lecture 11
Lecture 11
Lecture 11
Lecture No. 11
1
Activity Selection Problem
• Input: A set of activities S = {a1,…, an}
• Each activity ai has start time si and a finish time fi
such that 0 ≤ si < fi < ∞
• An activity ai takes place in the half-open interval [si
, fi )
• Two activities are compatible if and only if their
interval does not overlap
i.e., ai and aj are compatible if [si , fi ) and
[sj , fj ) do not overlap (i.e. si ≥ fj or sj ≥ fi )
• Output: A maximum-size subset of mutually
compatible activities
• Also Called Interval Scheduling Problem
Activity Selection Problem
• Brute Force Solution
All possible subsets
Running time: O(2n)
• “Greedy” Strategies:
Greedy 1: Pick the shortest activity, eliminate all activities
that conflict with it, and recurse.
Greedy 2: Pick the activity that starts first, eliminate all the
activities that conflict with it, and recurse.
Greedy 3: Pick the activity that ends first, eliminate all the
activities that conflict with it, and recurse.
Observe
• Greedy1 and Greedy2 does not work
• Greedy3 seems to work (Why?)
Notation
Notation
0, 𝑖𝑓 𝑗 = 0
𝑆𝑗 = ൝
max {𝑣𝑗 + 𝑆 𝑝 𝑗 , 𝑆 𝑗 − 1 }, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Interval Partitioning
Interval Partitioning
Lecture i starts at si and finishes at fi.
Goal:
Find minimum number of classrooms to schedule all
lectures so that no two occur at the same time in
the same room.
Answer
• Depth - Given a set of intervals, the depth of this
set is the maximum number of open intervals that
contain a time t.
Interval Partitioning
Lemma
In any instance of interval partitioning we need at
least depth many classrooms to schedule these
courses.
Proof
This is simply because by definition of depth there is
a time t and depth many courses that are all running
at time t. That means that these courses are mutually
in-compatible, i.e., no two of them can be scheduled
at the same classroom. So, in any schedule we would
need depth many classrooms.
Greedy Strategies
Greedy Strategies:
Greedy 1: Pick the shortest activity
- ascending order of fj - sj
Greedy 2: Pick the activity that starts first,
ascending order of sj
Greedy 3: Pick the activity that ends first
ascending order of fj
Greedy algorithm
Greedy algorithm
Consider lectures in increasing order of start time: assign
lecture to any compatible classroom.