TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Sorting Algorithm Cheat Sheet

229 pointsby gameguy43about 6 years ago

10 comments

swiftcoderabout 6 years ago
&gt; Radix sort looks fast, with its O(n)O(n) worst-case time complexity. But, if you&#x27;re using it to sort binary numbers, then there&#x27;s a hidden constant factor that&#x27;s usually 32 or 64 (depending on how many bits your numbers are). That&#x27;s often way bigger than O(\lg(n))O(lg(n)), meaning radix sort tends to be slow in practice.<p>The constant factor in radix sort isn&#x27;t the number of bits, it&#x27;s the number of digits. Since one typically sorts on a computer using 8-bit &#x27;digits&#x27;, that&#x27;s a constant factor of 4 or 8 (not 32 or 64).
评论 #19761735 未加载
ComputerGuruabout 6 years ago
Of course in the real world for problems where sorting is actually the bottleneck and not just something you want not to kill your app&#x27;s performance, you end up with things like timsort that destroy all these in practice.
评论 #19761840 未加载
评论 #19763202 未加载
评论 #19761987 未加载
saagarjhaabout 6 years ago
I think it&#x27;s important to mention that counting sort and radix sort are not &quot;true&quot; comparison-based sorts: they have additional requirements on the input data.
评论 #19761601 未加载
northisupabout 6 years ago
Who is still asking candidates to talk about sorting algorithms?<p>It is just trivia and has little to no bearing on if the candidate can actually do the job (unless the job relates to the runtime of sorting algorithms, of course).
评论 #19762189 未加载
评论 #19761615 未加载
评论 #19763545 未加载
评论 #19763328 未加载
评论 #19761413 未加载
评论 #19761720 未加载
评论 #19761772 未加载
gameguy43about 6 years ago
Original author here, happy to answer questions about data structures, algorithms, and coding interviews!
评论 #19761688 未加载
评论 #19761426 未加载
评论 #19760564 未加载
gameguy43about 6 years ago
Curious: did people notice that you can click on each algorithm and click the blue button to get a detailed write up of how it works? (Or is that too hard to find?)
评论 #19765276 未加载
GorgeRondeabout 6 years ago
There is also sorting networks. If you have to sort short list of items, it&#x27;s probably the best solution around.<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Sorting_network" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Sorting_network</a>
hopscotchabout 6 years ago
The best real sorting algorithms are often hybrid.<p>Would be nice to see mention of parallel sorting algorithms. These have basically linear speedup and you can do them on GPUs.<p>Obvious disclaimer that you should never care about your sorting algorithm choice until you need to. Performance is more often IO or memory related than compute. Tech interviews are daft, etc.
marvinjamesabout 6 years ago
Best case for heapsort is actually O(n). Build heap always takes O(n). Then e.g. when all keys are the same, the max-heapify call will take O(1) instead of O(logn).
评论 #19762620 未加载
CobrastanJorjiabout 6 years ago
feature request: make O(k) bright red, like O(n^2). As it stands, it looks nice and pleasant like O(1) but it&#x27;s honkin&#x27; terrifying.
评论 #19762267 未加载