4 ms·
some constructive feedback: one of the greatest features of quicksort is that it is an in-place algorithm, it doesn't use any additional storage. qsort cleveres
by lanna 10y ago
some constructive feedback: one of the greatest features of quicksort is that it is an in-place algorithm, it doesn'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 "less" and "greater" piles. as it is, your animation is great, but it doesn't really illustrate qsort, especially the most fundamental aspects that set it apart from other sorting algorithms.
- skidding 10y agoGood points. I'll think about this and read more on Quicksort. Do you think these aspects can be incorporated without adding extra baggage for beginners (the primary target for this visualizations)?
- brudgers 10y agoTo me, I think that the space savings is exactly what should be emphasized to beginners. I love functional programming as much as the next person...well maybe almost as much...but quicksort without mutation is not quicksort. Showing beginners quicksort with mutation pulls back the curtain on functional programming and reveals the wizard. Functional programming, so long as we have Von Neumann machines, is a layer of abstraction and who am I to argue with Abelson and the Sussmans that beginning programmers should be introduced to abstraction layers as quickly as possible?
- liamondrop 10y agoAbsolutely: https://www.cs.usfca.edu/~galles/visualization/ComparisonSort.html https://www.cs.usfca.edu/~galles/visualization/ComparisonSor...
- Asooka 10y agoWith so few elements, I think you can perform the in-place swap as one animation. Take the pivot out, put an arrow on the first and last elements in the list, then - if the left arrow points to an element greater than the pivot, swap the elements under the arrows and move the right arrow one cell left - else if the right arrow points to an element less than the pivot, swap the elements under the arrows and move the left arrow one cell right - else if one of the arrows points at the pivot, move the other arrow towards it until the two arrows point at the same cell, which now contains the pivot. You could show the full selection animation the first time and then just move all elements to their final places at once every subsequent time. I would also replace the random pivot selection with selecting the middle-valued element among the first, middle and last element of the array.
- bjarnagin 10y agoNice work! One other note, in addition to the comments here: the algorithm as it's currently written will drop repeated elements. You can easily fix that by changing `greater` to filter elements greater than or equal to the pivot.
- baby 10y agoI was watching this: https://www.youtube.com/watch?v=ywWBy6J5gz8 https://www.youtube.com/watch?v=ywWBy6J5gz8 and wondering why it was different from this post's animation.
- imh 10y agoIt depends on whether pedagogy is the primary goal. For teaching, the in-place implementation can come after the conceptual "pick a pivot, partition accordingly, then recurse" is made concrete.
- bastijn 10y agoI agree. I find https://visualgo.net/sorting https://visualgo.net/sorting to provide easier to understand animations. Also, the fruits are less understandable to me than simple numbers.