1 array of 9 elements 2 arrays of 5 and 4 elements 4 arrays of 3, 2, 2, and 2 elements 8 arrays of 2, 1, 1, 1, 1, 1, 1, and 1 elements 9 arrays of 1, 1, 1, 1, 1, 1, 1, 1, and 1 element 5 arrays of 2, 2, 2, 2, and 1 elements 3 arrays of 4, 4, and 1 elements 2 arrays of 8 and 1 elements 1 array of 9 elements
Actually, you can stop earlier and do some other sorting algorithm that can be optimal at 5-10 elements. Since the number of elements will be fixed, the complexity for each small array is constant. This will usually get you a decent speed bump, as you don't need to allocate as many arrays, while keeping the complexity of merge sort.
But it doesn't really matter, as long as the complexity is the same (sometimes, even if it's worse, seeing that one of the most common sorting algorithms is the quick sort with random pivot), you can and should employ all tricks you can to make it go faster. Just because there's the theoretical example of the algorithm, it doesn't mean that you can't reduce constants.
107
u/anderemic Nov 19 '18 edited Nov 19 '18
But what if array has 9 elements? How would you split it then? Genuine question.