ALGORITHMS
🇬🇧UK Edition🇨🇦Canada Edition🌐Global Tech
QuickSort vs MergeSort: Empirical Performance & Space Complexity Analysis
Elena Rostova
Staff Engineer & Algorithmic Specialist
Updated 02/09/20266 min read3 views
Overview
Sorting algorithms form the backbone of database indexing and operating system kernels. QuickSort operates in-place with O(1) auxiliary space, whereas MergeSort offers guaranteed O(N log N) time regardless of pivot selection.
python
def quicksort(arr):
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quicksort(left) + middle + quicksort(right)
print(quicksort([3, 6, 8, 10, 1, 2, 1]))Frequently Asked Questions (FAQ)
Q: Which sort is used in Python sort()?
Timsort, a hybrid derivative of MergeSort and InsertionSort.
Written by Elena RostovaAdSense EEAT Verified
Staff Engineer & Algorithmic Specialist. Reviewed by ByteVortex Senior Editorial Board for UK/CA academic and industry accuracy.