compare_methods()
Compare sorting methods on the given data.
Usage
compare_methods(data)Runs multiple sorting algorithms on the input data and returns a dictionary with timing and memory metrics for each method.
Parameters
data: list-
A list of comparable elements to sort.
Returns
dict-
A dictionary mapping method names to their performance metrics.
Notes
The following table summarizes the complexity characteristics of the sorting methods compared:
======== ========= =========== Method Speed Memory ======== ========= =========== Quick O(n log n) O(log n) Merge O(n log n) O(n) Bubble O(n^2) O(1) ======== ========= ===========
The speed column shows average-case time complexity. Memory shows auxiliary space complexity, excluding the input array.
For small datasets (n < 50), the differences between these methods are negligible due to constant factors.
Examples
>>> result = compare_methods([5, 3, 1])
>>> sorted(result.keys())[‘bubble’, ‘merge’, ‘quick’]