Energy and Time Complexity for Sorting Algorithms in Java
Kristina Carter, Su Mei Gwen Ho, Mathias Marquar Arhipenko Larsen, Martin Sundman, Maja H. Kirkeby
TL;DR
This study empirically demonstrates a strong linear relationship between energy consumption and time complexity for four classic sorting algorithms implemented in Java on a single-kernel setup. By converting input sizes to their corresponding time-complexity scales and applying linear regression, the authors show $R^2$ values exceeding 0.99 for Counting Sort, Merge Sort, and Quick Sort, and above 0.94 for Bubble Sort, indicating that time complexity is a robust predictor of energy use in sequential sorting. The work also reveals that theoretical worst-case inputs do not always yield the worst energy or wall time, with random inputs sometimes driving higher costs, and discusses limitations related to hardware, measurement techniques, and input-import noise. These findings provide a practical basis for software developers to consider time complexity as a surrogate for energy efficiency in single-threaded sorting tasks. The study further suggests avenues for extending the analysis to different hardware, programming languages, and broader algorithm classes.
Abstract
The article investigates the relationship between time complexity and energy consumption in sorting algorithms, focusing on commonly-used algorithms implemented in Java: Bubble Sort, Counting Sort, Merge Sort, and Quick Sort. The significance of understanding this relationship is driven by the increasing energy demands of Information and Communication Technology systems and the potential for software optimization to contribute to energy efficiency. If we find a strong correlation between time complexity and energy usage, it would enhance the ability of software developers to create energy-efficient applications. This quantitative study researches the execution of four selected sorting algorithms with input varying over input sizes (25000 to 1 million) and input order types (best, worst, and random cases) on a single kernel in a Java-enabled system. The input size is adjusted according to the type's maximum execution time, resulting in 136 combinations, totalling 12960 measurements. Wall time and the CPU energy consumption is measured using Intel's RAPL. Statistical analysis are used to examine the correlations between time complexity, wall time, and energy consumption. The study finds a strong correlation between time complexity and energy consumption for the sorting algorithms tested. More than 99% of the variance in energy consumption for Counting Sort, Merge Sort, and Quick Sort depend on their time complexities. More than 94% of the variance in energy consumption for Bubble Sort depends on its time complexity. The results affirm that time complexity can serve as a reliable predictor of energy consumption in sequential sorting algorithms. This discovery could guide software developers in choosing energy-efficient algorithms by considering time complexities.
