Solution Review: Weighted Scheduling Problem
Explore how to solve the weighted scheduling problem using different approaches including simple recursion, top-down memoization, and bottom-up dynamic programming. Understand their time and space complexities and learn how to optimize scheduling efficiently.
Solution 1: Simple recursion
Explanation
To find the profit-maximizing schedule, we need to check all possible schedules. How do we find all possible schedules? This is pretty simple given the fact that you have a helper function, lastNonConflict, that gives us the last event that did not clash with the event provided to it. We sort our schedule with the end times of all the events (line 21). Next, we start from the last event in our sorted schedule, i.e., the event that ended the last. Now if this event is part of the optimal schedule, all the other events that clash with it cannot be part of the optimal schedule. Thus, we find the last non-conflicting event and make a recursive call with it (line 17). Another option could be that this event is not part of the optimal event, so we recursively make a call to the event before it (line 18). In the end, we take the max of these two ...
Time complexity
At each step, we have two possible options to explore. One is to include the event in the schedule, ...