Activity Selection
A greedy problem where picking activities by earliest finish time lets you select the most non-overlapping activities. Sort by finish time, then adopt only the ones that don't overlap the previously chosen activity.
01Activity Selection
Explore How It WorksThe activities sorted by earliest finish time. The goal is to pick as many as possible without overlapping in time.
Pick A(1~3), the one that finishes first. Anything next has to start at 3 or later.
B starts at 2, before A is over, so it overlaps. Skip it.
C starts at 4, so it doesn't overlap A. Pick it, and the bar moves to 6.
D starts exactly at 6. No overlap, so pick it and move the bar to 8.
E starts at 5, running into D before it ends. Skip it.
Selection complete · A · C · D, three of them. Picking the earliest-finishing first always guarantees the maximum count.
02 Understand It Simply
For EveryoneChoosing the activity that finishes earliest leaves the most room afterwards, which yields the largest possible count.
Pick the activity that finishes earliest, then take only those that don't overlap your last pick.
That simple rule guarantees the maximum count.
- –Meeting-room and classroom assignment
- –task scheduling
03 Python Implementation
A clean, readable reference implementation of the core logic of Activity Selection.
04 Frequently Asked Questions
FAQWhat is Activity Selection?+
A greedy problem where picking activities by earliest finish time lets you select the most non-overlapping activities. Sort by finish time, then adopt only the ones that don't overlap the previously chosen activity.
What is the time complexity of Activity Selection?+
The time complexity of Activity Selection is O(n log n). Follow the step-by-step visualization to see exactly why.
Where is Activity Selection used?+
Meeting-room and classroom assignment, task scheduling.
What's a simple analogy for Activity Selection?+
Choosing the activity that finishes earliest leaves the most room afterwards, which yields the largest possible count.
