What is the main goal of the Activity Selection Problem?
To select the maximum number of activities that don't overlap in time from a given set of activities with start and finish times.
Click to reveal answer
beginner
Which algorithmic approach is commonly used to solve the Activity Selection Problem efficiently?
A greedy algorithm that selects activities based on earliest finish time first.
Click to reveal answer
intermediate
Why do we sort activities by their finish times in the Activity Selection Problem?
Sorting by finish times ensures that when we pick an activity, we leave as much room as possible for the remaining activities to fit without overlapping.
Click to reveal answer
intermediate
In the Activity Selection Problem, after selecting an activity, what is the next step?
Skip all activities that start before the selected activity finishes, then select the next activity that starts after the current one finishes.
Click to reveal answer
intermediate
What is the time complexity of the Activity Selection Problem when using the greedy approach?
O(n log n) due to sorting the activities by their finish times, where n is the number of activities.
Click to reveal answer
What is the first step in solving the Activity Selection Problem using a greedy approach?
ASelect activities randomly
BSort activities by their start times
CSelect the longest activity first
DSort activities by their finish times
✗ Incorrect
Sorting activities by finish times helps pick the activity that frees up the schedule earliest.
After selecting an activity, which activities are skipped next?
AActivities that start before the selected activity finishes
BActivities that finish before the selected activity starts
CActivities with the longest duration
DAll remaining activities
✗ Incorrect
We skip activities that overlap by starting before the current activity finishes.
What does the Activity Selection Problem maximize?
ATotal duration of selected activities
BNumber of non-overlapping activities
CSum of start times
DNumber of overlapping activities
✗ Incorrect
The goal is to select the maximum number of activities that do not overlap.
Which of these is NOT true about the greedy solution to the Activity Selection Problem?
AIt always picks the activity with the earliest finish time next
BIt guarantees an optimal solution
CIt requires checking all subsets of activities
DIt runs in O(n log n) time due to sorting
✗ Incorrect
The greedy approach does not check all subsets; it uses a simple selection after sorting.
If two activities have the same finish time, which one should be chosen first in the greedy approach?
AEither one, since finish times are equal
BThe one with the later start time
CThe one with the earlier start time
DThe one with the longer duration
✗ Incorrect
If finish times are equal, either can be chosen as they finish simultaneously.
Explain how the greedy algorithm solves the Activity Selection Problem step-by-step.
Think about choosing activities that free up time earliest.
You got /5 concepts.
Describe why sorting by finish time is crucial in the Activity Selection Problem.
Consider how finish times affect scheduling.
You got /4 concepts.
Practice
(1/5)
1. What is the main goal of the Activity Selection Problem?
easy
A. Find the activity with the longest duration
B. Sort activities by their start times
C. Select the maximum number of activities that don't overlap
D. Calculate the total time of all activities
Solution
Step 1: Understand the problem goal
The Activity Selection Problem aims to choose activities that do not overlap in time.
Step 2: Identify the objective
The objective is to select the maximum number of such non-overlapping activities.
Final Answer:
Select the maximum number of activities that don't overlap -> Option C
Quick Check:
Goal = Max non-overlapping activities [OK]
Hint: Pick activities with earliest finish times first [OK]
Common Mistakes:
Choosing activities based on longest duration
Sorting by start time only
Trying to maximize total duration instead of count
2. Which of the following Go code snippets correctly sorts activities by their finish time for the Activity Selection Problem?
Sorted activities by finish: (1,4), (3,5), (0,6), (5,7), (8,9), (5,9)
Step 2: Select activities greedily
Select (1,4), next (5,7) since 5 >= 4, then (8,9) since 8 >= 7. Total selected = 3.
Final Answer:
3 -> Option B
Quick Check:
Max non-overlapping = 3 [OK]
Hint: Count activities with start >= last selected finish [OK]
Common Mistakes:
Counting overlapping activities
Not sorting by finish time
Starting count from zero instead of one
4. Identify the bug in this Go code snippet for the Activity Selection Problem:
package main
import (
"fmt"
"sort"
)
type Activity struct {
start, finish int
}
func main() {
activities := []Activity{{1, 3}, {2, 5}, {4, 7}}
sort.Slice(activities, func(i, j int) bool { return activities[i].start < activities[j].start })
count := 1
lastFinish := activities[0].finish
for i := 1; i < len(activities); i++ {
if activities[i].start >= lastFinish {
count++
lastFinish = activities[i].finish
}
}
fmt.Println(count)
}
medium
A. Sorting by start time instead of finish time
B. Initializing count to zero instead of one
C. Using wrong comparison operator in if condition
D. Not importing the fmt package
Solution
Step 1: Check sorting criteria
The code sorts activities by start time, but the greedy approach requires sorting by finish time.
Step 2: Understand impact of sorting
Sorting by start time can cause incorrect selection of activities, leading to wrong count.
Final Answer:
Sorting by start time instead of finish time -> Option A
Quick Check:
Sort by finish time needed [OK]
Hint: Always sort by finish time, not start time [OK]
Common Mistakes:
Sorting by start time
Forgetting to update lastFinish
Starting count at zero
5. Given the following activities with start and finish times: [(1, 2), (3, 4), (0, 6), (5, 7), (8, 9), (5, 9)], what is the maximum number of activities that can be selected without overlap using the Activity Selection Problem approach?