This is why I only use bogo sort
Programming
All things programming and coding related. Subcommunity of Technology.
This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.
With a small enough data set, bogo sort will perform just as well as an O(1) algorithm for sorting for both ascending and descending order!
That's using your noodle!
Use it or lose it, right?
O(n)
Yup, it's why O(N+10) and even O(2N) are effectively the same as O(N) on your CS homework. Speaking too generally, once you're dithering over the efficiency of an algorithm processing a 100-item dataset you've probably gone too far in weeds. And optimizations can often lead to messy code for not a lot of return.
That's mostly angled at new grads (or maybe just at me when I first started). You've probably got bigger problems to solve than shaving a few ms from the total runtime of your process.
Just a little nitpicking, O(N+10) and O(2N) are not "effectively" the same as O(N). They are truly the same.
Aren't the most commonly accepted sorting algorithms O(nlog(n))? Quicksort? Mergesort? Those are considered bad?
I mean, it is entirely reasonable that "bad" is the best performance you can hope for while sorting an entire set of generally comparable items.
If you can abuse special knowledge about the data being sorted then you can get better performance with things like radix sort, but in general it just takes a lot of work to compare them all even if you are clever to avoid wasted effort.
Yeah, you're right, it doesn't make sense to say that O(f(n)) is good or bad for any algorithm. It must be compared to the complexity of other algorithms which solve the same problem in the same conditions.
The labels are from the perspective of viewing the space of all possible functions of element set size to operations, so they don't apply to any particular problem an algorithm is attempting to solve (that space is often smaller).
I've been wrong about the performance of algorithms on tiny data sets before. It's always best to test your assumptions.
god i wish i had this image when i was learning algorithms. i always just guessed for some of the exam questions 🙃