Quicksort explained IKEA-style
27 comments
·September 21, 2025a022311
saghm
If we're willing optimize for aesthetic over ability to help understand, I'll nominate demonstration via Hungarian Folk Dance[1] as a candidate for the best medium to depict sorting algorithms, which I first saw during a lecture years ago when the professor pulled up on of the videos to show us in class
[1]: quicksort is shown here, but the channel has plenty of others https://youtu.be/3San3uKKHgg
aDyslecticCrow
Such a internet classic. I have never once searched for it, yet seen it dozens of times.
thomasmg
I agree, IKEA instructions are great. A bit related are railroad diagrams, like the one of the JSON syntax [2].
I worked on Rubik's cube solving instructions for beginners [1] (for my children initially), but then I found it would be so much better if the instructions are IKEA style. (Then I vibe-coded a Rubik's cube 2D and 3D model, and now I stopped working on this. Something for later.) For the cube, I want to implement the algorithm, and then from the program create IKEA instruction (or a mix of IKEA and railroad diagram). That way I can be sure I didn't skip any steps in the instructions.
[1] https://github.com/thomasmueller/rubiks/blob/main/README.md [2] https://www.json.org/json-en.html
porridgeraisin
> Rubik's cube 3D model
Google had a doodle way back when... That let you play the cube on the search page.
I found it hosted here [1] although I'm sure they have a doodles archive. Didn't check it myself but it should be possible to take the JS from that and use it for our purposes.
[1] https://sites.google.com/site/populardoodlegames/rubik-s-cub...
klibertp
If I didn't know how quicksort works - and I had to learn, since for some reason in FP languages quicksort is typically next after "hello world" - I would struggle to make sense of the pictures, I think. However, it's absolutely brilliant as a memory refresher: it packs so much info in so little space that it's insanely efficient. I imagine it would pair well with a good textbook on algorithms.
jason_s
> since for some reason in FP languages quicksort is typically next after "hello world"
How does FP handle the random selection?
musicale
Missing the instruction panel where the customer is attempting to follow the baffling instructions and has to use a wired phone to call the store for help.
Getting quicksort's boundary conditions right (avoiding off-by-one errors, infinite recursion, etc.) can be tricky.
Another popular algorithm that can be hard to get right is binary search.
JdeBP
BINÄRY SEARCH has you covered. (-:
HarHarVeryFunny
Seems to be:
1) Pick a random (dice roll) pivot
5) Move all values less than pivot before it, all greater than after it
6) Recurse to sort elements before & after pivot
NooneAtAll3
at best I can see trouble in interpreting "throw cube and shade a bar" as "choose randomly"
but if you don't understand it at all... I have bad news for you
jrmg
I can understand it after some deciphering, but I think that’s only because I already know quicksort. I’d be interested in seeing if anyone new to sorting algorithms finds it illuminating.
Then again, maybe that’s not important to the author - it is a pretty funny illustration to those in the know.
tlahtinen
I'm a programmer (after a fashion) but I don't know how quicksort works.
This is how I understand it after reading these instructiöns, without looking up any further explanation:
1. Choose a random element as the 'center' point of the sort
2. That element defines the maximum 'height' (value)
3. Anything that is larger than that value, is moved to the right side of the 'center'
4. Anything that is smaller than that value, is moved to the left side of the center. After this, the array is partially sorted.
5. The sorting process is repeated on both 'sides' independently, picking a new random center element and so on
What isn't clear, is how often the process needs to be repeated, or when the algorithm 'knows' that the sorting has been finished - surely it can't be just three iterations?
By now I've already looked up how the algorithm actually works, but the above is what I got out of the illustration :)
xnx
Would be better if the die had lettered sides that matched up to the bar positions. With "3" it's hard to be certain it's the bar position and not the height.
Dan42
This is cool, but missing a LOT of details between steps 4 and 5, which is the meat of the quicksort. Actually, the first and last elements of step 4 would be swapped, which means the order depicted in step 5 is incorrect.
HarHarVeryFunny
Isn't that more of an implementation detail?
I'd guess if you care more about speed than memory it might be faster to just move elements into new array - sequence through old array appending to start/end of new array according to pivot comparison. You'd be moving every element vs leaving some in place with a swap approach, but the simplicity of the code & branch prediction might win out.
Dan42
I'm pretty sure the swapping is a fundamental part of the quicksort algorithm, not a mere implementation detail. That's the reason quicksort is an in-place algorithm.
BaardFigur
Don't call it quicksört (aka quicksørt/quicksœrt). It's so jarring to read. It's pronounced line the vocal sound in "learn"
koolba
Step 4 is that one step you have to move all the pieces around repeatedly to match the paper until you realize one them is upside down and the other side is lightly sanded.
pmarreck
Brilliant. Never heard of this site.
kazinator
It looks like Step 3 may be using Hoare's original partitioning method with two pointers, which is laudable.
f33d5173
You're misunderstanding. They don't explain how to do partitioning at all. Step 3 is just tagging the elements that are above the partition element, which there happen to be two of.
junga
I miss the default IKEA instruction to have two people for building even the tiniest piece of furniture.
LordGrey
Step #5 is very much a "draw the rest of the fucking owl" step.
rfl890
I ignored the arrows and interpreted it as "move all elements lower than the marker in order to the left of the marker, and move all elements higher than the marker in order to the right of the marker". It's not clear, but if you use a bit of intuition you can come to this conclusion. Personally it took me about 5 seconds.
xandrius
Have you ever learnt about Quicksort? If so, it might give you an edge on what to expect.
This is so cool! Not only is the design similar, but just like the real IKEA instructions, I can't understand them! This is as realistic as it gets.