4 ms·
If you know the structure of your data (or lack thereof) a priori, of course you can select an algorithm that outperforms one that is strong in a more general s
by ntenenz 12y ago
If you know the structure of your data (or lack thereof) a priori, of course you can select an algorithm that outperforms one that is strong in a more general sense. An insertion sort is O(N) for nearly sorted data (hence why it's used as a part of many hybrid sorts) and, on data that's already sorted, will outperform ANY sort you throw at it. However, you would never use it on data that you know is reversed.
In other words, calling a merge sort a "faster sort" is a complete misnomer. Saying it's faster for a certain sequence of data is far more accurate (and also a bit of a "no shit" statement since one could construct a multitude of sequences where the opposite is also true).
- tetha 12y agoThat's why the best sorting algorithm is to generate sorted data, if that's possible without too much overhead.