r/compsci • u/TopcatTomki • Aug 14 '13
Algorithims Everyone Should Know?
What are some of you're favourite algoritms or concepts that you think everyone should know, whether they solve problems that crop up frequently, or are just beautiful in their construction?
379
Upvotes
View all comments
Show parent comment
10
u/blexim Aug 14 '13
Quicksort's worst case complexity is affected in a big why by your pivot selection strategy. You can make it O(n log n) by using the median element as your pivot (which takes O(n) time to find). In practice you wouldn't want to do this because you end up slower for pretty much any practical case. Mergesort is indeed easier to analyse, but it's not used in practice as much as quicksort. This isn't because it has a fancy name, it's because it's an in place sort (so uses less memory) and is empirically faster for most applications.