8 ms·
I'm curious why you'd choose an algorithm that on average takes O(n log n) comparisons with a O(n^2) worst case versus simply iterating O(n)? Unless there are
by Yeroc 15y ago
I'm curious why you'd choose an algorithm that on average takes O(n log n) comparisons with a O(n^2) worst case versus simply iterating O(n)?
Unless there are other requirements I don't see why you'd suggest sorting the elements.
- bostonpete 15y agoI certainly wouldn't choose that algorithm. I thought the correct solution was obvious enough that I could joke about it...