What is a good way to merge non intersecting sets in a list to end up with denseley packed sets?
I am not sure whether it will give an optimal solution, but would simply repeatedly merging the two largest non-overlapping sets not work?
I'm currently doing this by using a sort of a greedy algorithm by iterating over the sets from largest to smallest set. What would be a good algorithm to choose if i'm more concerned about finding the best solution rather than efficiency?
Details:
1) Each set has a predefined range
2) My goal is to end up with a lot of densely packed sets rather than reducing the total number of sets.
Example: Suppose the range is 8.
The sets might be: [1,5,7], [2,6], [3,4,5], [1,2] , [4], [1]
A good result would be [1,5,7,2,6,4], [3,4,5,1,2], [1]