TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Sorting Algorithm Cheat Sheet

229 点作者 gameguy43大约 6 年前

10 条评论

swiftcoder大约 6 年前
&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 未加载
ComputerGuru大约 6 年前
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 未加载
saagarjha大约 6 年前
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 未加载
northisup大约 6 年前
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 未加载
gameguy43大约 6 年前
Original author here, happy to answer questions about data structures, algorithms, and coding interviews!
评论 #19761688 未加载
评论 #19761426 未加载
评论 #19760564 未加载
gameguy43大约 6 年前
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 未加载
GorgeRonde大约 6 年前
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>
hopscotch大约 6 年前
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.
marvinjames大约 6 年前
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 未加载
CobrastanJorji大约 6 年前
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 未加载