The server generates a random array in PHP, then sorts it with ALL selected algorithms at once (up to 6) - watch side by side how differently eleven sorts work through the exact same input.
-
Big O notation describes an algorithm's time complexity - "how much slower it gets as the input grows" - by showing the growth rate's order of magnitude, not the exact running time.
O(n²) ("quadratic") means doubling the input roughly quadruples the number of steps - this is what makes bubble sort effectively unusable on large arrays.
O(n log n) ("linearithmic") is substantially better: doubling the input only a bit more than doubles the number of steps - quicksort, merge sort and heap sort all fall into this class, which is why they scale well to large datasets.
Theoretical complexity isn't everything, though: in practice quicksort tends to outperform merge sort on most real-world inputs, despite its worst case degrading to O(n²) - the visualization above illustrates this well.
A stable sort keeps the original order of elements with equal keys - important when sorting several times (e.g. by name, then by age). Comparison sorts have an O(n log n) lower bound; radix sort sidesteps it by not comparing at all and using the digits of the elements instead.
This site uses Google Analytics to measure visits. This requires your consent - see the privacy policy for details. Privacy Policy