I'm looking for an efficient algorithm to perform the following: given an array of N items, sort it in a way so that items come as M equal groups, where each group is unsorted, but groups are sorted between each other (all elements in one group are less than any element of the next group).
The easiest way is to just sort the whole array. But it's inefficient, especially if the number of groups is much smaller than the total number of items (e.g. sort a million items into 5 groups).
Currently I've settled on using the quickselect algorithm (specifically, it's Floyd-Rivest variation) that sorts an array into 2 unsorted groups, and then applying it M-1 times. An significant improvement may be to apply divide-and-conquer approach to quickselect, first sorting the array into two groups, then sorting each half, etc., until we have M groups. Kind of a generalization of unordered partial sorting problem.
But I have a gut feeling that there might be a simpler and more efficient approach to the problem. Is there anything I'm missing? Any ideas? I need this for improving bulk insertion performance in my RBush JavaScript library (an efficient R*-tree implementation).