Earlier quoted context omitted.
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.
BINÄRY SEARCH has you covered. (-: * https://idea-instructions.com/binary-search/
Quicksort explained IKEA-style
31–40 of 142 posts
Re: Quicksort explained IKEA-style
#32It looks like Step 3 may be using Hoare's original partitioning method with two pointers, which is laudable.
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.
A random pivot is... fine. It can't solve the worst case perf problem, and it won't ensure high performance for other cases either, but hey you did pick a pivot and this algorithm is often fast enough.
Re: Quicksort explained IKEA-style
#33Earlier quoted context omitted.
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.
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.
shame, shame, I should have double-checked before posting.
Re: Quicksort explained IKEA-style
#34Re: Quicksort explained IKEA-style
#35If 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.
> since for some reason in FP languages quicksort is typically next after "hello world" How does FP handle the random selection?
Re: Quicksort explained IKEA-style
#36Step #5 is very much a "draw the rest of the fucking owl" step.
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.
Re: Quicksort explained IKEA-style
#37Earlier quoted context omitted.
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 va…
Yeah, that's about it. Personally, I'm not sure I'd get this much out of the picture, but you can see the information is there. > surely it can't be just three iterations? To save others a search: you stop when the remaining sub-arrays are sorted by definition (ie. [] or [x]/size of 0 or 1).
They'll have a highly optimised small sort and use that whenever sorting very small things. So e.g. IPN Sort the Rust stdlib unstable sort will do this for 16 items, even though for a big slice it'd quick sort them by default, once it's down to say 10 items they're going to the specialised small sort.
Any serious "fast" sort in 2025 will be a hybrid, using several of these classic sorting algortihms, plus other insights to produce the overall best solution to their problem on modern hardware.
Re: Quicksort explained IKEA-style
#38After that you just have to understand exactly how partitioning works and get the ranges correct.
Re: Quicksort explained IKEA-style
#39If 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.
> since for some reason in FP languages quicksort is typically next after "hello world" How does FP handle the random selection?
You could use a monad/external state for an OS-level RNG, or define a purely functional PRNG
Re: Quicksort explained IKEA-style
#40Unfortunately, the merge sort instructions doesn't make sense to me, specifically step 3.