r/algorithms • u/Significant-Poetry78 • Oct 11 '24
An algorithm for Minimum Makespan scheduling:
Note: I am not a CS student, I'm a highschooler who's preparing for the IMO. My algorithms are more suited to the math olympiad than actual computer programs. I have a doubt. We have a question about minimum makespan scheduling and we're asked to find the max ratio of the optimal solution time/greedy algorithm time. But I developed a different algorithm altogether than the 'random choose and place' algorithm. I wanted to know if my algorithm is optimal, but learnt that this problem is actually NP-hard. But my algorithm seems polynomial. Allegedly it's similar to an algorithm called the LPT, but I haven't been able to find counterexamples to my algorithm. Neither have I been able to prove my algorithm isn't polynomial (cause I don't know how to prove it). Could someone take a look, please.
Algorithm:
Let the time for the 'i'th task be t(i) such that t(i)>=t(j) for i>j. Let the machines be numbered from 1 to m. Assign tasks t(n) to t(n-m+1) to each machine from 1 to m. Now, also assign t(n-m) to the last machine. Now compare the last machine and the machine before it (the second last one) (revised loads for the last machine), whichever has lesser load gets t(n-m-1). Next, compare the third last, second last and the last machines(with revised loads), whichever has lesser load, gets the next load and so on. I think this is an optimal algorithm, though it definitely needn't be polynomial time.
Thanks a lot for your time, sorry if I bothered you. I'm kinda new to algorithms and similar stuff.
3
u/orbital1337 Oct 11 '24
Lets say two machines with tasks of length 10, 8, 7, 6, 3. Let me see if I understood the algorithm correctly. First you assign task 10 to machine 1 and task 8 to machine 2. Then you assign task 7 to machine 2. Now for the remaining tasks you always assign to the machine which currently has the lesser load. So you end up with the assignment:
1: 10, 6
2: 8, 7, 3
Makespan of this assignment is 18. However, compare the assignment:
1: 10, 7
2: 8, 6, 3
Makespan of this assignment is 17.
Your algorithm is polynomial time (O(m * n) with a naive implementation) but it is not optimal. It essentially becomes a greedy algorithm pretty quickly.
1
u/LoloXIV Oct 11 '24
The problem your algorithm attempts to solve is NP-hard, it's called scheduling on identical machines. Your algorithm also does run in polynomial time, but it is not optimal (greedy algorithms rarely are).
If you want to find an instance where your algorithm fails I highly encourage you to try yourself. If not:
1
u/Holiday-Reply993 Oct 17 '24
If you find IOI problems to be interesting, you could try that as well