I have been examining the TimSort algorithm implementation in both Android and Oracle JDK, and I noticed that when sorting a sub-range of an array, the temporary array used for merging is always ensured to have a capacity equal to half the length of the whole array. This seems to potentially waste memory when sorting a sub-range that is smaller than half the length of the whole array.
I wonder if this behavior is intended or if it is a possible oversight in the implementation. Has anyone else noticed this, and is there any way to optimize the temporary array size when sorting sub-ranges of an array in both Android and Oracle JDK?
I would appreciate any insights or suggestions on this issue. Thank you!
I tried sorting a sub-range of an array using TimSort in both Android and Oracle JDK, and I expected the temporary array used for merging to be resized to match the length of the sub-range rather than half the length of the whole array.