Given that we have a collection of videos of different types (say types A,B and C,...), we are looking for an efficient algorithm to order these objects into a playlist so that we have maximum dispersion. That is, we want to make sure that two videos from A will not be placed back to back, if that can be avoided. The playlist will be repeating (it starts over when it ends. So this aspect should also be considered).
What would be an efficient algorithm that could perform the above with a good dispersion?
Example Input:
- 5 objects of type A (A1, A2, A3, A4, A5)
- 3 objects of type B (B1, B2, B3)
Output - Not Optimal
A1, B1, A2, B2, A3, B3, A4, A5
This is not optimal because after A4, A5 plays and then the playlist loops back and A1 plays. Now we have played 3 videos from type A back to back.
An Optimal Output
A1, B1, A2, A3, B2, A4, B4, A5
This is optimal because we have only 2 videos of same type playing back to back.
Note that the algorithm should work for varying number of types and videos.