diff options
author | Kuan-Wei Chiu <visitorckw@gmail.com> | 2023-11-10 19:53:14 +0300 |
---|---|---|
committer | Tzung-Bi Shih <tzungbi@kernel.org> | 2023-11-13 07:46:42 +0300 |
commit | d131f1f3b459980d38a59adc3598c96cc3a6ad5e (patch) | |
tree | 2ab9c10ad6f5d29d8191bb721cab24035560ecf1 /tools/perf/scripts/python/export-to-sqlite.py | |
parent | 49e380795414039f7b3bd44c121104f31738dcf1 (diff) | |
download | linux-d131f1f3b459980d38a59adc3598c96cc3a6ad5e.tar.xz |
platform/chrome: sensorhub: Implement quickselect for median calculation
The cros_ec_sensor_ring_median function currently uses an inefficient
sorting algorithm (> O(n)) to find the median of an array. This patch
replaces the sorting approach with the quickselect algorithm, which
achieves an average time complexity of O(n).
The algorithm employs the median-of-three rule to select the pivot,
mitigating worst-case scenarios and reducing the expected number of
necessary comparisons. This strategy enhances the algorithm's
efficiency and ensures a more balanced partitioning.
In the worst case, the runtime of quickselect could regress to O(n^2).
To address this, alternative algorithms like median-of-medians that
can guarantee O(n) even in the worst case. However, due to higher
overhead and increased complexity of implementation, quickselect
remains a pragmatic choice for our use case.
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Link: https://lore.kernel.org/r/20231110165314.1559285-1-visitorckw@gmail.com
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
Diffstat (limited to 'tools/perf/scripts/python/export-to-sqlite.py')
0 files changed, 0 insertions, 0 deletions