Skip to content

Commit c0c9542

Browse files
authored
Refactor activity_selection function documentation
Updated docstring and added a check for empty input.
1 parent c0853e3 commit c0c9542

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎greedy_methods/activity_selection.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
The Activity Selection Problem is a classic problem in which a set of activities,
3-
each with a start and end time, needs to be scheduled in such a way that
4-
the maximum number of non-overlapping activities is selected.
3+
each with a start and end time, needs to be scheduled in such a way that the
4+
maximum number of non-overlapping activities is selected.
55
This is a greedy algorithm where at each step,
66
we choose the activity that finishes the earliest
77
and does not conflict with previously selected activities.
@@ -34,7 +34,12 @@ def activity_selection(activities: list[tuple[int, int]]) -> list[tuple[int, int
3434
3535
>>> activity_selection([(5, 9), (1, 2), (3, 4), (0, 6)])
3636
[(1, 2), (3, 4), (5, 9)]
37+
38+
>>> all(activity_selection == [] for x in ([], {}, None, False, 0, 0.0))
39+
True
3740
"""
41+
if not activities:
42+
return []
3843

3944
# Step 1: Sort the activities by their end time
4045
sorted_activities = sorted(activities, key=lambda activity: activity[1])

0 commit comments

Comments
 (0)