PROBLEM You are running a physics experiment with n complicated steps that you must do in order, and students sign-up for some steps to help. Your experiment requires n steps, and each of the m students gives you a list of which steps they can help out with (steps require special skills). From experience, you know things run most smoothly when you have as little switching of shifts as possible.
For example, if your experiment has <1, 2, 3, 4, 5, 6> steps
Student 1: <1, 2, 3, 5>
Student 2: <2, 3, 4>
Student 3: <1, 4, 5, 6>
Your optimal solution would be:
-- > Student 1 <1, 2, 3>, Student 2 does no steps, Student 3 does <4, 5, 6>. Only 1 switch
Another example if your experiment has 8 steps <1, 2, 3, 4, 5, 6, 7, 8>
Student 1: <5, 7, 8>
Student 2: <2, 3, 4, 5, 6>
Student 3: <1, 5, 7, 8>
Student 4: <1, 3, 4, 8>
Your optimal solutions could be any one of these:
-- > Student 1 does no steps, Student 2 does <2, 3, 4, 5, 6>, Student 3 does <1,7, 8>, Student 4 does no steps .2 switches (student 3 does step 1, student 2 does up to 6, student 3 picks up again to do 7 and 8)
-- > Student 1 does <7, 8>, Student 2 does <2, 3, 4, 5, 6>, Student 3 does <1>,Student 4 does nothing. 2 switches
-- > Student 1 does no steps, Student 2 does <2, 3, 4, 5, 6>, Student 3 does <7,8>, Student 4 does <1>. 2 switches
Given: n number of steps, m number of students that give you a list of steps (sorted) they can participate in. Assume there's a lookup table where you can find if student X signed up for step Y in O(1), so no need to factor that into your runtime.
Find: An optimal way to schedule students to steps such that there is the least amount of switching as possible.
The present algorithm in python chooses an optimal switching sequence.
The output gives the sequence showing at each step, the sub-list and also the min and max elements in each selected sub-list
For the sets
the algorithm gives the result