Here's a lesson about the difference between theory and practical applications. Everyone knows about bubble Sort and merge Sort - they're probably the first two sorting algorithms you learned. Everyone also knows that (1) bubble sort sucks and (2) this is due to the fact that its average time complexity is O(n^2), aka the worst time complexity. It even generally performs worse than things like insertion sort and selection sort , the "a D- is still a passing grade" of sorting algorithms. While all these things are true, there's a more important truth: always test your code. While reading The Imposter's Handbook by Rob Conery the other day and flipping through the comparison sort algorithms he provides, I decided, Why not actually test out this code? And, the speed test demon that I am, my test involved sorting out his [23,4,42,15,16,8] array one million times with bubble sort and with merge sort, and I got this res...
Comments
Post a Comment