9 ms·
Quicksort explained IKEA-style
- ggm 1y agoThe recursion element should be a reproduction of the entire IKEA instruction in miniature
- bobsmooth 1y agoI love this, it's so adorable.
- a022311 1y agoThis 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.
- musicale 1y agoMissing 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 1y agoBINÄRY SEARCH has you covered. (-: * https://idea-instructions.com/binary-search/ https://idea-instructions.com/binary-search/
- NooneAtAll3 1y agoat 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
- xnx 1y agoWould 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.
- jrmg 1y agoI 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 1y agoI'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 :)
- klibertp 1y agoYeah, 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).
- giancarlostoro 1y agoI kind of get it, but just like Ikea instructions, you start second guessing yourself, then you realize, its BACKWARDS after you flip back 5 pages in when something doesn't fit.
- a022311 1y agoReminds me of when I was assembling some drawers and put in the bottom of one upside-down. At least I wasn't the one using them...
- giancarlostoro 1y agoAre you on about the ones where the bottom is carboard that could go either way? LOL I hate building those. Ikea instructions are like an Easy to Medium level test in reverse engineering skills, with occasional EXPERT TIER SUPREME level skills needed because of subtleties.
- klibertp 1y agoIf 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 1y ago> since for some reason in FP languages quicksort is typically next after "hello world" How does FP handle the random selection?
- klibertp 1y agoThey use the first element. Like, it's random enough, right? :) (I mean, it still works, but goes badly for lists already sorted in reverse, etc.)
- shpongled 1y agoThere's no problem with randomness in FP? You could use a monad/external state for an OS-level RNG, or define a purely functional PRNG
- shawn_w 1y agoIt's usually quicksorting a linked list, where a random pivot, median of three, etc. are terrible for performance. (Merge sort is of course the natural sort for lists, but qs is like 2 lines of Haskell so it gets demoed for being clever)
- tmtvl 1y agoJust do the Sedgewick thing and take the median of the first, middle, and last elements.
- Arch-TK 1y agoQuicksort in FP? Surely you mean mergesort, that's the classic FP sorting example.
- kazinator 1y agoIt looks like Step 3 may be using Hoare's original partitioning method with two pointers, which is laudable.
- f33d5173 1y agoYou'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.
- tialaramex 1y agoWell, to the extent a picture can explain they say choose at random. That's what the dice shown is about. 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.
- f33d5173 1y agoI'm talking about step 5. The elements just magically migrate to the correct position, whereas in the real algorithm they would be moved individually.
- tialaramex 1y agoIt would be clearer if they weren't magically sorted early. Maybe they can improve in a later edition of the instructions. I think maybe Lego would cut away to show one layer of repetition for example.
- 010101010101 1y agoThe curly braces with the arrow pointing down are the thing implying the recursive calls on that set of elements until you’re done.
- f33d5173 1y ago
- junga 1y agoI miss the default IKEA instruction to have two people for building even the tiniest piece of furniture.
- QuantumNomad_ 1y agoHow many people do you need to assemble a BILLY bookshelf? Three! One to read the manual. One to be instructed by the first on how assemble it. One to break up the fight when the first two get into fisticuffs over step 4 in the manual.
- HarHarVeryFunny 1y agoSeems 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
- Dan42 1y agoThis 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 1y agoIsn'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 1y agoI'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.
- Dan42 1y agoActually you're right, it is an implementation detail. The original isn’t mistaken, it’s just showing the lo-to-hi partitioning pass rather than the from-both-ends version I had in mind when I implemented quicksort before. shame, shame, I should have double-checked before posting.
- deleted 1y ago[deleted]
- thomasmg 1y agoI 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 https://github.com/thomasmueller/rubiks/blob/main/README.md [2] https://www.json.org/json-en.html https://www.json.org/json-en.html
- porridgeraisin 1y ago> 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-cube https://sites.google.com/site/populardoodlegames/rubik-s-cub...
- Cockbrand 1y ago> I'm sure they have a doodles archive You are correct: https://doodles.google/ https://doodles.google/ It doesn't seem to have the Rubik's cube, though
- gerdesj 1y ago"I agree, IKEA instructions are great" They are until you hit one for something that is so simple it does not really need instructions, then you will end up in a tail spin! We bought a window shade puller thing and it had instructions! Lego are also superb at instructions, for obvious reasons. I've put together a couple of modern Lego models with a lot of pieces and they are still as good as I remember 40+ years ago. I have to say that the model of the Chinese Year of the Dragon beastie from 2024? was pretty tricky.
- 1y ago
- LordGrey 1y agoStep #5 is very much a "draw the rest of the fucking owl" step.
- rfl890 1y agoI 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 1y agoHave you ever learnt about Quicksort? If so, it might give you an edge on what to expect.
- deleted 1y ago[deleted]
- imajoredinecon 1y agoI agree it does a pretty good job of communicating that. I think the other commenters are pointing out that doesn’t show how to efficiently get all the smaller items left of the partition and larger ones to the right. While that’s probably second nature to most people who’ve taken an algorithms class or done a decent amount of programming, I guess it’s up for interpretation how obvious it would be to the “intended audience” of the ikea manual
- tialaramex 1y agoI can't tell if this was serious. This really is how a pure Quicksort works, you just recursively apply this same algorithm and the result is sorted. In contrast the initial circles approach can't be recursed to draw the rest of the fucking owl.
- TacticalCoder 1y ago
- saghm 1y agoIf 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 https://youtu.be/3San3uKKHgg
- aDyslecticCrow 1y agoSuch a internet classic. I have never once searched for it, yet seen it dozens of times.
- stevage 1y agoSo what is the best algorithm when you have a bunch of people and want them sorted in order of, say, birthday.
- TeMPOraL 1y agoTell the people with any CS experience they're not allowed to talk, and then let everyone just go for it. The first part is crucial, because if the group has two or more people exposed to CS courses, they'll invariably start negotiating the optimal algorithm to use while trying to recall the actual implementation, thus preventing any actual sorting from taking place.
- lucaslazarus 1y agoPresumably some kind of Radix Sort: you ask the crowd to split up and group together by month, let the people in each group self-sort and organize however they'd like, and then just concatenate the sorted queues together
- ninkendo 1y agoOr to make “concatenate” more physical, divide an area into 12, one for each month in order, then in each area, people sort themselves. This is similar to the best design we have for the fastest way to board a plane: take people in a dozen or so “chunks”, then have each chunk stand in a sorting area atop a diagram of the airplane, one chunk at a time. A group enters the area and sorts themselves by standing near the place on the diagram where their seat is, then boards the plane in line. As each chunk boards, they’re already in the right order so that nobody is blocking anyone while trying to stuff their overhead luggage. I’m not sure if any company has implemented the system but there was some test a company did of a bunch of boarding techniques and it was the most efficient.
- koolba 1y agoStep 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.
- BaardFigur 1y agoDon'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"
- TeMPOraL 1y agoDoesn't matter - it's just a FEJKA manual anyway.
- QuantumNomad_ 1y agoBut it does matter. I’m not sure if you are already aware and did it intentionally or if it was a happy accident, but FEJKA really is named that because it’s a real word in Swedish that comes from English with meaning very near to how you used it there. Swedish adjective “fejk” comes from English adjective “fake”. Swedish “fejka” is the verb form of the same, with the meaning similar to one of the English meanings of the verb form: To give the impression that something is a certain way when it is not. And that’s what the FEJKA series of products happen to be. Artificial plants that look like they are real, even though they are not :) And so back to the point of naming these pretend IKEA manuals. If they are to really look real without being real, they should be named in a way that would make even swedes second guess whether they might be real manuals. (When seen in a context where it was not immediately stated that they are imitations.)
- TeMPOraL 1y ago> I’m not sure if you are already aware and did it intentionally or if it was a happy accident, but FEJKA really is named that because it’s a real word in Swedish that comes from English with meaning very near to how you used it there. I guessed as much; I'm Polish but know enough English that I burst into laughter when I first saw a fake plant labeled FEJKA in a local IKEA store. In fact, I couldn't believe they'd be this direct with naming. But then I don't know enough Swedish to translate the other names. (Still wonder what kind of geopolitical order they meant when they named their wardrobe system PAX. Or is it just because you can pack absurd amount of things into it?) > If they are to really look real without being real, they should be named in a way that would make even swedes second guess whether they might be real manuals. (When seen in a context where it was not immediately stated that they are imitations.) Fair enough. I was just making an unsophisticated joke about the FEJKA line :).
- pmarreck 1y agoBrilliant. Never heard of this site.
- bigswede 1y agoNice! KVICK SÅRT, would be the most correct swenglish title though.
- Agentlien 1y agoI think sort would be even better because it's less Swenglish. It's the base for sorting in Swedish (sortera) after all. Sört does really bother me since it sounds so wrong (almost like the u in blur). Sårt use closer to how Swedes would pronounce the English word sort, that's true. At least they changed the first word to Kvick because it means the right thing and sounds about right. And it happens to be my family name.
- CyberDildonics 1y agoI think a much better explanation would be to just say that it partitions the values into a lower and higher half. Then it recursively does the same thing to each half. After that you just have to understand exactly how partitioning works and get the ranges correct.
- NetMageSCW 1y agoHow do you decide which weight to use to create two halves?
- tialaramex 1y agoIn their example they choose a random pivot, is that what you're asking about? There are a number of strategies but random will indeed work and is simple to explain.
- CyberDildonics 1y agoYou use a value called a pivot, not a weight, and there are many ways and endless variations you can read about, including just choosing a random value from the current range.
- theogravity 1y agoThis surprisingly made this easy to remember for me. Unfortunately, the merge sort instructions doesn't make sense to me, specifically step 3.
- jfengel 1y agoIt's not a merge sort, it's just a partition. Mark every element greater than your pivot as "move right". Then step 4 marks every smaller element as "move left". Step 5 actually does that. You don't really need to split that into 3 steps, though it looks a bit more like a real IKEA diagram with the extra steps.
- NetMageSCW 1y agoWrong diagram - “merge sort”.
- NetMageSCW 1y agoThe key to step 3 (of the merge sort) is the little nx in the middle that tells you to repeat step 3 n times. Each time, you take a right or left branch based on if the new weight from the half plank is lighter or heavier than the current weight. You also have to understand that step 1 means you recursively merge sort each half before you merge the two sorted halves.
- ozgung 1y agoI’ve just completed reading all 8 posters on the site. For some reason I find them easier to understand than any written content, code or math. They are all intuitive. It was fun and engaging to solve their notation and meaning they want to convey. The one with AVL trees was the most useful to me.
- jerjerjer 1y agoAlso checked the PDF compilation and it is a surprisingly effective way to explain algorithms considering there are no words at all.
- stabbles 1y agoIt should be possible to better explain in IKEA style how to perform partitioning with swapping. In its current form it can make people fall into a quadratic complexity trap.
- Awesomedonut 1y agoOh my goodness, I'm in love with this site! One of my favourite things about HN is all of the cool sites I discover through the community :D
- Daunk 1y agoSeeing a random Ö hurts my Swedish brain. Especially when "Sort" is Swedish already.
- chuckadams 1y agoIt's a https://en.wikipedia.org/wiki/Metal_umlaut https://en.wikipedia.org/wiki/Metal_umlaut
- deleted 1y ago[deleted]
- cnxhk 1y agoI am wondering if we could use any llm to generate similar graphs lol.
- toyhank 1y agoI have use nano banana to generate some like this https://postimg.cc/PN0Z1vz2 https://postimg.cc/PN0Z1vz2
- labrador 1y agoOr there's quick sort in Hungarian dance if you prefer Quick sort with Hungarian, folk dance https://www.youtube.com/watch?v=3San3uKKHgg https://www.youtube.com/watch?v=3San3uKKHgg
- hinkley 1y agoWhy am I disappointed they didn’t sort the dancers by height? Very cool demo.
- hdjrudni 1y agoI was confused by step (3). The right pillar doesn't need to move right because it's already to the right of the chosen pillar. I guess what it's trying to say is just "mark it as needing to be to the right", and then do the opposite in (4) and then (5) is where things actually move.
- deleted 1y ago[deleted]
- elephant81 1y agoI've tried to have AI generate these types of visual instructions from text without luck. Perhaps it was the IKEA-style guide I needed.
- shib71 1y agoMy first thought was that it would be explaining Quicksort using an Ikea warehouse as a metaphor, to show how different algorithms suit different constraints. As for the actual Ikea-style instruction pamphlet... I suspect that making it was very helpful for the author. But I don't think the result would have helped me as a novice. It took some work for me to understand the diagram, and I've used Quicksort.
- adastra22 1y agoSounds like they captured the IKEA manual experience very well!
- crdrost 1y agoFor me the key was just application to figuring out if any cards are missing in a deck by sorting it. Assume spades < clubs < diamonds < hearts, and ascending order for cards for all suits. Once you know the principle you can switch to US playing card order if you want. In your first pass, divide the deck into black and red cards. Then divide black into spades and clubs. Then divide spades into <= 7 and >7. Then insertion sort the cards <= 7, then insertion sort the cards > 7, spades are now sorted. Clubs come next, divide into <= 7 and > 7, insertion sort, and combine. Split diamonds and hearts, repeat with diamonds, repeat with hearts. “What about the pivot thing?” Well, that's because we don't know the midpoint of our set in a typical sort. So instead you can just grab a random card and then go through the deck to find all cards < that card. If you want slightly fewer passes, use median of three.
- moi2388 1y agoThat’s how I sorted cards long before knowing about sorting algorithms
- eru 1y agoA lot of people have trouble with understanding recursion. Perhaps that's where they struggle with quicksort? Luckily, there's a simple non-recursive quicksort variation. It goes like this: Simplifying assumption: all items are distinct. Invariant: Throughout our procedure, we will have a bunch of bags arranged in a sequence before us from left to right. Items in a bag are all jumbled up, but all items in bag A are smaller than any item in bag B, if A comes before B in our sequence. Now, we start by stuffing all our items into a single bag. We repeat the following: - Pick an arbitrary bag X. Anyone will do, you can pick at random, or your favourite bag, or always the left-most or whatever. Only one condition: bag X has to have more than a single element left in it. - Grab a random element E out of X as your pivot. - Categories all elements of X into: smaller than E, E itself, and bigger than E. Stick these categories into their own bags and place them into our sequence in the appropriate order. Repeat until all bags left have one or fewer elements.
- theodpHN 1y ago"Bublé Sort": Animated GIF explanation of bubble sort using tracks from Michael Bublé's 'Let It Snow!' album https://communities.sas.com/t5/Graphics-Programming/Fun-With-SAS-ODS-Graphics-quot-Bublé-Sort-quot/td-p/286659 https://communities.sas.com/t5/Graphics-Programming/Fun-With...
- gnarbarian 1y agoI hate quick sort. merge sort has a better big O, is cleaner conceptually, and is trivial to run concurrently. bah humbug
- Agentlien 1y agoThis was actually a really neat refresher. The name feels like such a near miss though... Kvick (beyond being my surname) does mean quick and I see they changed to it from kwick to make the title "more Swedish". Great! But sört? That's not a Swedish word and feels very "trying to seem Swedish without knowing any Swedish". That letter would be pronounced somewhat like the u in blur. Meanwhile sort in Swedish is sortera. Sort itself does mean sort as in kind/type. So perhaps Kvick Sort would be the best version of the name?
- friendzis 1y agoIKEA-fication of terms in other languages (although on the general internet that tends to converge mostly on English) is a long standing meme. It's not supposed to be swedish, it's not even supposed to sound strictly swedish, it's supposed to sound and look ikea-ish
- Agentlien 1y agoI understand where you're coming from. From the perspective of someone with no knowledge of Swedish that's a clear distinction. From my perspective as a Swede, however, making it sound Swedish is the same as making it sound Ikea-ish. Because Ikea products all have names which are either Swedish words or typical Swedish names.
- BrandoElFollito 1y agoI am French and our language is also often abused for fun. I find it funny as well and I am actually quite glad that it makes it on the meme-o-meter because it means it is popular. You rarely hear fun things about, say, Finnish.
- SiempreViernes 1y agoI think Kvik Ordning would be more IKEA
- jalk 1y ago
- Dwedit 1y agoI never understood why use Quick Sort when you could use something else instead, like Merge Sort. Using a pivot seems backwards compared to something guaranteed to be NLOGN time.
- froh 1y agohere you go: https://idea-instructions.com/merge-sort/ https://idea-instructions.com/merge-sort/ and I think in this discussion we marvel the presentation, not the algorithm per se.
- SJC_Hacker 1y agoQuick sort can be done in place Merge sort requires additional space
- froh 1y agothis page is fun. and it has a large number of algorithms "explained" Ikea style. I think it's great to explain them to others. I think it doesn't work as a teaching tool per se. it needs someone who understands the algorithms already, to decide and explain what's going on. thank you for sharing
- Al-Khwarizmi 1y agoDo people actually find IKEA explanations helpful? I always thought they were a cost-cutting measure to avoid text in different languages. For me, they tend to be incomprehensible. Maybe because I have a very verbal style of learning, but I think it's not only that because I do find Lego instructions easy. This captured the IKEA experience perfectly in the sense that I can understand it because I already know Quicksort, but otherwise, I don't think I would figure it out.
- chillfox 1y agoIKEA instructions are kinda like a worse version of Lego instructions. But in general I could not imagine assembling a 3d shape without pictures/drawings. Using text instructions for 3d shapes sounds like a nightmare.
- Al-Khwarizmi 1y agoNot saying 100% pure text instructions without images would make sense, but for me, some text alongside the drawings would help immensely.
- bombela 1y agoFunny. I have always found their instructions great. I am quite visual.
- trwhite 1y ago> Choosing the dividing element at random is a good strategy to avoid bad worst-case runtime. Please can someone explain what’s meant by “bad worse-case runtime”?
- Onavo 1y agoWorst case is n^2, where the chosen element is either the largest or the smallest element. Then the result is an insertion sort across the whole list. (Not sure if the order would matters, don't remember off the top of my head).
- geon 1y agoIt kind of annoys me when people just adds diacritics to fake swedish/ikea names. They are not for decoration, but makes it a completely different sound. How about the direct translation “snabbsortering”? Or even “kvicksortering”, to more resemble the original? Both are perfectly valid swedish.
- dncornholio 1y agoIkea instructions are great because they explain something simple. That's pretty hard to do it wrong in the first place.
- revanwjy 1y ago[flagged]
- deleted 1y ago[deleted]
- s_fekete 1y agoHello everyone! Author of IDEA here - great to hear that this has caught some attention. As it happens, these instructions were developed in the course of a 1st-year undergraduate course, so it's tried and tested in teaching noobs. There is even a song-and-dance version (sorry, German lyrics): https://youtu.be/iq_TcSvWaY4 https://youtu.be/iq_TcSvWaY4 Cheers, Sándor Fekete, Professor for Algorithmics, TU Braunschweig https://www.ibr.cs.tu-bs.de/users/fekete/ https://www.ibr.cs.tu-bs.de/users/fekete/