0% found this document useful (0 votes)
2 views

Activity Selection Problem (1)

The Activity Selection Problem involves scheduling a set of competing activities that require exclusive access to a common resource, aiming to select the largest subset of mutually compatible activities. The most effective strategy is the Earliest Finish Time First approach, which involves sorting activities by their finish times and iteratively selecting non-overlapping activities. The algorithm has a time complexity of O(n log n) and is proven to be optimal through the greedy choice and optimal substructure properties.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Activity Selection Problem (1)

The Activity Selection Problem involves scheduling a set of competing activities that require exclusive access to a common resource, aiming to select the largest subset of mutually compatible activities. The most effective strategy is the Earliest Finish Time First approach, which involves sorting activities by their finish times and iteratively selecting non-overlapping activities. The algorithm has a time complexity of O(n log n) and is proven to be optimal through the greedy choice and optimal substructure properties.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Activity Selection

Problem
Problem
Statement

You are tasked with scheduling several competing activities that require exclusive use of a
common resource, such as a conference room. Given a set S = {a1, a2, ..., an} of n activities,
where each activity ai has a start time si and a finish time fi (0 ≤ si ≤ fi < ∞), the goal is to select
the largest subset of mutually compatible activities. Two activities ai and aj are considered
compatible if their intervals [si, fi) and [sj, fj) do not overlap, i.e., if fi ≤ sj or fj ≤ si.
The objective is to find a maximum-size subset of S such that all activities in the subset are
mutually compatible.
i 1 2 3 4 5 6 7 8 9 10 11
1 3 0 5 3 5 6 7 8 2 12
4 6 6 7 9 9 10 11 12 14 16

EXAMPLE
{a1, a4, a8, a11} is a largest subset of mutually compatible events, and another largest subset is
{a2, a4, a9, a11}.
List of Greedy Strategies:
1. Select the activity with the earliest start time that is compatible with previously selected
activities.
2. Select the activity with the shortest duration (fi-si).
3. Select the activity with the fewest conflicts (i.e., the least overlap with other activities).
4. Select the activity with the earliest finish time that is compatible with previously selected
activities.
The most effective strategy for the activity selection problem is the Earliest Finish
Time First strategy.
Algorithm:
GREEDY-ACTIVITY-SELECTOR (activities, n)
1. Sort the activities by their finish times f[i], in ascending order.
2. A ← {activities[1]}
3. k ← 1
4. for m ← 2 to n do
5. if activities[m].start ≥ activities[k].finish then
6. A ← A ∪ {activities[m]}
7. k ← m
8. return A
Running Time:
1. Sorting activities:
sorting the n activities by their finish time takes:
O(n log n)
2. Iterative Solution:
Iterating through the sorted activities to select non-overlapping ones takes:
O(n)
3. Total time Complexity:
O(n log n) + O(n) = O(n log n)
PROOF OF CORRECTNESS
Greedy choice property
The greedy choice property ensures that the locally optimal choice at each step leads
to a globally optimal solution. For this algorithm, the greedy choice is selecting
the earliest finishing activity that is compatible with the previously selected
activities.
Proof by Induction:
Consider any non-empty subproblem Sk and let am be an activity in Sk with the earliest finish time.
Then am is included in some maximum-size subset of mutually compatible activities of Sk. 1
PROOF OF CORRECTNESS:
Greedy choice property:
The greedy choice property ensures that the locally optimal choice at each step leads to a
globally optimal solution. For this algorithm, the greedy choice is selecting the earliest
finishing activity that is compatible with the previously selected activities.
Proof by Induction:
Consider any non-empty subproblem and let be an activity in with the earliest finish time.
Then is included in some maximum-size subset of mutually compatible activities of Sk.

Claim: Let be a maximum-size subset of mutually compatible activities in , and let be the activity in with the
earliest finish time. If = , we are done, since we have shown that belongs to some maximum-size subset of
mutually compatible activities of S

Base case (for S₁):


Consider the first activity S₁ with only one activity a₁ in it.
The greedy choice is to select a₁ because it has the earliest finish time in S₁.
A₁ = {a₁} is trivially the maximum-size subset of mutually compatible activities.
Hence, the theorem holds for the base case.
Inductive Hypothesis:
Assume that for any subset with k activities, the greedy choice (the activity with the earliest finish
time) is included in some maximum-size subset of mutually compatible activities.

Inductive Step:
Now consider , a subproblem with k+1 activities.
Let am be the activity in with earliest finish time.
According to the greedy choice, am is selected.
Case 1: is in the maximum subset
If is already included in the maximum subset , the theorem holds for .
Case 2: is not in the maximum subset
Let be a maximum-size subset of mutually compatible activities of that does not include am.
we can construct a new subset as follows:
= ( - {}) ∪ {} where is the activity in Ak+1 with the earliest finish time such that ≥ . Observation-1: is still a
subset of mutually compatible activities.
Replacing with am does not create conflicts because ≤ (greedy choice ensures am has the earliest
finish time).
Observation-2: The new size of the subset is | | = | |.
Since, includes , it is a maximum-size subset of mutually compatible activities.

Optimal substructure property:


The optimal substructure property ensures that an optimal solution to the problem contains optimal
solutions to its subproblems. For the iterative algorithm, after selecting , the problem reduces to selecting the
maximum number of non-overlapping activities from the remaining set.
Proof by contradiction:
The activity selection problem exhibits optimal substructure, meaning that if is the maximum size
subset of mutually compatible activities in , then:
= ∩ is the maximum-size subset of mutually compatible activities in , and
= ∩ is the maximum-size subset of mutually compatible activities in , where is the activity chosen as part of .
Problem Decomposition:
⇒ Suppose is the set of activities between ai and aj, such that < < < , where is an activity in that is part of an
optimal solution.
Let be the maximum-size subset of mutually compatible activities in .
Let = ∩ and = ∩
Decomposition Formula:
By construction, the optimal solution for can be expressed as:
= ∪ { } ∪ , where | | = | | + 1 + | |
Contradiction:
We aim to prove that both and are optimal. Assume, for contradiction, that or is not optimal.

Case-1: is not optimal:


Suppose there exists another subset of mutually compatible activities in such that:
||>||
• Construct a new subset for as follows:
• = ∪ {} ∪
• The size of is: | | = | | + 1 + | |
• since, | | > | |, it follows that | | > | |.
• This contradicts the assumption that is the maximum-size subset of mutually compatible activities in
• Case-2: is not optimal:
• Suppose there exists another subset of mutually compatible activities in such that:
• | |>||
• construct a new subset for as follows:
• = ∪ {} ∪
• The size of is: | | = | | + 1 + | |.
• Since | | > | |, it follows that | | > | |.
• .This again contradicts the assumption that is the maximum-size subset of mutually compatible
activities in .
• In both cases, we arrive at a contradiction. Hence, the assumption that or is not optimal must be false.
Observation-1: is the maximum-size subset of mutually compatible activities in .
Observation-2: is the maximum-size subset of mutually compatible activities in .
Thus, the activity selection problem satisfies the optimal substructure property.

You might also like