Scheduling Classes
Get to know the scheduling classes problem and its solution using greedy algorithms.
The next example is slightly more complex. Suppose we decide to drop out of computer science and change our major to Applied Chaos. The Applied Chaos department offers all of its classes on the same day every week, called “Soberday” by the students (but interestingly, not by the faculty). Every class has a different start time and a different ending time: AC 101 (“Toilet Paper Landscape Architecture”) starts at 10:27pm and ends at 11:51pm; AC 666 (“Immanentizing the Eschaton”) starts at 4:18pm and ends at 4:22pm, and so on. In the interest of graduating as quickly as possible, we want to register for as many classes as possible. (Applied Chaos classes don’t require any actual work.) The university’s registration computer won’t let us register for overlapping classes, and no one in the department knows how to override this “feature.” Which classes should we take?
Finding the largest non-overlapping subset of rectangles: a problem of scheduling classes
More formally, suppose we’re given two arrays and listing the start and finish times of each class; to be concrete, we can assume that for each , for some value (for example, the number of picoseconds in Soberday). Our task is to choose the largest possible subset so that for any pair , either or . We can illustrate the problem by drawing each class as a rectangle whose left and right x-coordinates show the start and finish times. The goal is to find the largest subset of rectangles that doesn’t overlap vertically.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy