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.

Show HN: Illustrated Quicksort algorithm

187 pointsby skiddingover 8 years ago

15 comments

bogomipzover 8 years ago
This is neat. If you enjoyed this you might also like the Hungarian folk dancers demonstrating sorting algorithms on youube:<p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=ywWBy6J5gz8" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=ywWBy6J5gz8</a>
评论 #13645840 未加载
评论 #13649139 未加载
skiddingover 8 years ago
Hi. This is my 2nd algoritm visualization. Creating them is fun.<p>Besides designing the illustrations, I&#x27;ve spent a lot of time crafting the framework so expect more of these in the future. Ongoing effort, but also tried to make the codebase approachable for others to learn from and be able to contribute: <a href="https:&#x2F;&#x2F;github.com&#x2F;skidding&#x2F;illustrated-algorithms" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;skidding&#x2F;illustrated-algorithms</a><p>How would you make algorithms fun? Looking forward to ideas and feedback. Thanks!
评论 #13643483 未加载
lannaover 8 years ago
some constructive feedback: one of the greatest features of quicksort is that it is an in-place algorithm, it doesn&#x27;t use any additional storage. qsort cleverest trick is to switch an element greater than the pivot with one smaller in a single step, and all of that is lost in the animation when the first thing it does is to group the fruits into the &quot;less&quot; and &quot;greater&quot; piles. as it is, your animation is great, but it doesn&#x27;t really illustrate qsort, especially the most fundamental aspects that set it apart from other sorting algorithms.
评论 #13649000 未加载
评论 #13647272 未加载
评论 #13643730 未加载
评论 #13646449 未加载
skiddingover 8 years ago
Update: I realize the featured example is not the most optimal Quicksort implementation. I doesn&#x27;t even handle duplicates. Indeed this variant was chosen primarely because of its aesthetics.<p>While I&#x27;d like to keep the mission of this project to &quot;illustrating the basic mechanics of algorithms as elegantly as possible&quot;, I realize this can be a) annoying for people who understand the specifics in depth, and b) not enough (or confusing) for people just picking this up. Which is why I&#x27;m thinking of creating an info page for each algorithm to:<p><pre><code> - Outline the limitations of the featured version - List a number of possible improvements (e.g. pivot strategies) - Link to external resources for complete examples &amp; docs </code></pre> Open discussion. What do you think?
评论 #13648432 未加载
snackaiover 8 years ago
Personally I find <a href="https:&#x2F;&#x2F;visualgo.net&#x2F;" rel="nofollow">https:&#x2F;&#x2F;visualgo.net&#x2F;</a> to be more helpful. I don&#x27;t think the fruits are too intuitive.
评论 #13643695 未加载
Rabeiover 8 years ago
Good work, looks great!<p>I have the following comments, hope you find them useful: * I find counter intuitive that the animation goes up, i think it should go down, but that probably just me. * Would recommend using something different than fruit which is probably one of the last things that comes to mind when thinking of ordered sets, also the picture keeps getting in the way of me sorting lexicographically in my mind. * A per step mode would also come in handy.
评论 #13644060 未加载
blinryover 8 years ago
If you enjoy visual or interactive explanations, we&#x27;re currently building a community for that on Reddit: <a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;explorables&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;explorables&#x2F;</a>
skiddingover 8 years ago
Update 2: I&#x27;ve taken action to try to alleviate some of the confusion and integrate the helpful feedback you&#x27;ve sent me.<p><pre><code> - Added Disclaimer to clarify the project mission and limitations - Created Footnotes section for insights collected from the community </code></pre> Both can be found here: <a href="https:&#x2F;&#x2F;github.com&#x2F;skidding&#x2F;illustrated-algorithms&#x2F;blob&#x2F;master&#x2F;README.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;skidding&#x2F;illustrated-algorithms&#x2F;blob&#x2F;mast...</a><p>Thanks!
kbrover 8 years ago
Hey, love it! I know that you know it can handle duplicates, but a simple fix can work here.<p>Make an array called `equal` before making the `less` and `greater` arrays.<p><pre><code> const equal = arr.filter(i =&gt; i === pivot); </code></pre> Then, instead of adding the pivot, add the equal array.<p><pre><code> return [ ...quicksort(less), ...equal, ...quicksort(greater) ]</code></pre>
notduncansmithover 8 years ago
This was cool, the highlighted code tour is a great touch.<p>For anyone else who enjoyed this, you might also enjoy this blog post full of animated algorithms by Mike Bostock: <a href="https:&#x2F;&#x2F;bost.ocks.org&#x2F;mike&#x2F;algorithms&#x2F;" rel="nofollow">https:&#x2F;&#x2F;bost.ocks.org&#x2F;mike&#x2F;algorithms&#x2F;</a>
babyover 8 years ago
That&#x27;s amazing. Just two questions<p>1) on quicksort:<p><pre><code> const less = list.filter(i =&gt; i &lt; pivot); const greater = list.filter(i =&gt; i &gt; pivot); </code></pre> Wouldn&#x27;t this be faster:<p><pre><code> less = what&#x27;s &lt; pivot greater = the rest </code></pre> 2) What is the algorithm people use?
评论 #13646241 未加载
评论 #13646206 未加载
评论 #13646208 未加载
gigatexalover 8 years ago
Thank you for this. The work to both understand the algorithm and then animate it, much appreciated
vinylkeyover 8 years ago
That&#x27;s snazzy, good work!<p>I found myself wanting to set my own initial order of the list to see what some specific edge cases (already sorted, one element off from being sorted, in reverse order, etc) look like.
hellofunkover 8 years ago
There was another interesting animated sorting page I found on here many months ago. I haven&#x27;t seen it in the comments yet and I can&#x27;t find it anywhere, but this stuff is cool.
评论 #13646541 未加载
ameliusover 8 years ago
Why do people keep using Quicksort as an example?<p>I find Mergesort to be much more intuitive. And better yet, it has a much better worst-case performance.
评论 #13643777 未加载
评论 #13647384 未加载
评论 #13643676 未加载