Slashdot Mirror


Sorting Algorithms — Boring Until You Add Sound

An anonymous reader writes "Anyone who's ever taken a programming course or tried to learn how to code out of a book will have come across sorting algorithms. Bubble, heap, merge — there's a long list of methods for sorting data. The subject matter is fairly dry. Thankfully, someone has found a way to not only make sorting more interesting, but easier to remember and understand, too."

118 comments

  1. Easily amused by Peach+Rings · · Score: 0, Flamebait

    Sorting is not a boring problem, and what are you 5 years old being amused by zoop-zap noises?

    1. Re:Easily amused by 0racle · · Score: 2, Insightful

      Yes

      --
      "I use a Mac because I'm just better than you are."
    2. Re:Easily amused by Anonymous Coward · · Score: 1, Funny

      Wonderful. Just what we needed for the next generation of science fiction movies. Audible sorting!

    3. Re:Easily amused by tenco · · Score: 1

      Dunno why you're offtopic. You're right. At least about the "sorting not boring"-part :)

    4. Re:Easily amused by oldspewey · · Score: 2, Funny

      I'll create an audio interface using Visual Basic ... see if I can track an IP address.

      --
      If libertarians are so opposed to effective government, why don't they all move to Somalia?
    5. Re:Easily amused by spazdor · · Score: 1

      Bloop, ping!

      --
      DRM: Terminator crops for your mind!
    6. Re:Easily amused by gmagill · · Score: 1

      I watched/listened as I sucked the bong, the visual patterns converging certainly enhance the sounds, in a satisfying way. cough.

    7. Re:Easily amused by Frnknstn · · Score: 1

      I totally agree. Look, I am sorry to make this a "what has become of slashdot?" post, but WTF? Algorithms are INTERESTING. If using sound to illustrate sorting is interesting, then it is only interesting because the algorithms themselves are interesting, and you are unable to see that without the idiotic noises, through no fault of your own.

      --
      If it's in you sig, it's in your post.
    8. Re:Easily amused by DaVince21 · · Score: 1

      Even if learning sorting was a piece of cake, or at least not boring, for you, that doesn't mean that everyone else can do it just as easily. I know I had my fair share of problems trying to learn and use them, and some of these visualizations do actually seem to help a bit in the "understanding" department.

      Granted, an older compared visualization using MIDI (the one with the guitar notes) was better at doing this, but still.

      --
      I am not devoid of humor.
  2. QuickBasic did this by Bananenrepublik · · Score: 3, Informative

    Anybody who did their first programming steps with QuickBasic will remember that it came with a demo that did just this. Anyway, the videos are still fun to watch.

    1. Re:QuickBasic did this by commodore64_love · · Score: 4, Informative

      Ditto MS BASIC 7(?) on the old 1985 Amiga - included demos with sound.

      Plus TV shows, especially scifi ones, do this all the time. The computers don't have to make noise but the audio engineer added the sound to keep the show from being dull.

      --
      "I disapprove of what you say, but I will defend to the death your right to say it." - historian Evelyn Beatrice Hall
    2. Re:QuickBasic did this by afex · · Score: 1

      Anybody who did their first programming steps with QuickBasic

      fyi, remember that the freshman in high school right now were BORN in 1996. Heck, i started my BSEE in '01 and i barely made the cutoff for playing around with quickbasic. Though i was quite fond of the gorillas demo game... : )

  3. Sorting Out Sorting by SilverEyes · · Score: 3, Interesting

    Does anyone remember "Sorting Out Sorting" (1980)? Best sorting video ever made. This is the same thing, it's good, but it was done thirty years ago. Also, "Pointy Does Pointers" (not an adult film, I swear).

    --
    Interesting.
    1. Re:Sorting Out Sorting by maxwell+demon · · Score: 2, Informative

      Do you mean this? Because as far as I can see, that one doesn't illustrate the sorting algorithm itself with sound. Disclaimer: I only watched the first three minutes.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    2. Re:Sorting Out Sorting by SilverEyes · · Score: 3, Funny

      I did watch it again after I posted my comment, I was wrong. I misremembered the video. The annoying sounds are unrelated to the algorithm.

      This guy did have not-annoying sounds related to the algorithm. Also the quality is much higher.

      --
      Interesting.
    3. Re:Sorting Out Sorting by EyelessFade · · Score: 1

      Obligatory watch on the first algorithm course at my local university.

    4. Re:Sorting Out Sorting by publiclurker · · Score: 1

      We always showed this in a continuous loop during the engineering open house. Free popcorn was provided by the local branch of the ACM.

    5. Re:Sorting Out Sorting by MikeTheGreat · · Score: 2, Interesting

      My initial reaction was "Really? Seriously?? How does this make the algorithm any more interesting, easier to understand, or easier to remember? I mean hey - I like 80's console-sounds as much as the next guy, but they're not really adding anything."

      Then it hit me that (apparently) many people haven't seen the algorithms visualized like this before. As someone who's been teaching this stuff for years, I've always handed out links to visualizations like this (even if they did lack the retro-hip sound effects :) ). As a matter of fact, I think that one of the first big demonstrations of Java was an applet that demonstrated
      various sorting algorithms [citation needed :) ]

      Anyways, if you're interested in this sort of thing, the link I've been using is:
      http://www.sorting-algorithms.com/

      I've heard good things about this place, but haven't looked through it extensively:
      http://algoviz.org/

      (You know, in all the years I've been on Slashdot, I don't think I've ever wanted to create a new top-level post instead of responding to someone else's comment.... until now. Which is why I can't find the button to do so. I'd love for someone to (politely, with good humor) point out the obvious button that I'm missing)

    6. Re:Sorting Out Sorting by perlmangle · · Score: 1

      You reply to the main story, up top. Look for the box that contains "The Fine Print:" and then hit 'reply'.

    7. Re:Sorting Out Sorting by maxwell+demon · · Score: 1

      Well, given the new Web 2.0 interface, it might depend on your browser (I never tried it on anything but Firefox, so I don't know), not to mention that you can select between different interfaces, but if your Slashdot interface looks remotely like mine, there should be three possibilities to reply:

      The first possibility has the advantage that it's always visible (provided that your browser supports it, also you probably have to have JavaScript enabled, and it might be invisible anyway if you are looking at the story and not the comments), but it isn't exactly a button, but a link, so it doesn't exactly fir your question: In the floating box which, tells you how many comments are there, and has a fancy interface to collapse/expand the comments, which is almost as intuitive as the old dropdown menu from the pre-Web 2.0 times, but has the advantage that you can train your mouse abilities better, there's also a link "Reply", directly right of the link saying "[Number] more", and (at least for me) partially obscured by an icon which shows a small piece of paper with a pencil lying on it (it also might be a pen, at the small size it's hard to tell).

      The second option has the disadvantage that you have to scroll to the correct place, below the story, but above the comments. There's a grey bar, which on the right hand side contains again two links "[Number] more" and "Reply" (again there's the pencil/paper icon, but this time it doesn't partially obscure the link). However it again doesn't fit your demand for a button.

      Finally there's a third option which is the easiest to find, because unlike the two links mentioned before, it isn't very small, and which in addition fits best your demand for a button because it at least somewhat looks like a button, although looking at the page source reveals that it's again just a link. That button-link is at the very end of the page, below the comments, and to the right of another button-link which (you guessed it -- but I bet you didn't guess completely correct) contains the text "Get [Number] More Comments", and to the left of another button-link which says "Prefs" from which I conclude that whoever wrote this didn't know how to correctly spell "Preferences" (because given the large horizontal space available I cannot think of another reason to shorten it). Note, however, that this button-link lacks the paper-pencil icon. However this doesn't affect the functionality.

      So in short, if you insist on a button, you're out of luck (you might, however, be able to get that by changing your preferences to another interface). However if you are content with a link that looks like a button, you can use the one on the end of the page. And if you are willing to use a link that also looks like a link, you can in addition use one of the other two links I mentioned.

      OK, I hope this explanation fits your demand. If not, sorry, I've got no better humor to offer.

      --
      The Tao of math: The numbers you can count are not the real numbers.
  4. No Quicksort? by gus+goose · · Score: 4, Insightful

    Feel like I'm complaining about a poll with a missing option, but, honestly ....:(

    gus

    --
    .. if only.
    1. Re:No Quicksort? by maxwell+demon · · Score: 2, Funny

      I also noticed that they have Gnomesort, but not KDEsort. :-)

      --
      The Tao of math: The numbers you can count are not the real numbers.
    2. Re:No Quicksort? by kvezach · · Score: 3, Insightful

      No thinking outside of the box -- no radix sort? Seriously!

    3. Re:No Quicksort? by jgagnon · · Score: 1

      What would an XKCDsort look like?

      --
      Remember to maintain your supply of /facepalm oil to prevent chafing.
    4. Re:No Quicksort? by Tanktalus · · Score: 3, Funny

      I was looking for Bogosort myself, actually.

    5. Re:No Quicksort? by Anonymous Coward · · Score: 0

      And no Bogosort? Or Stoogesort? LAAAAAME!

    6. Re:No Quicksort? by tepples · · Score: 1

      Quicksort is the special case of radix sort with 2 bins.

    7. Re:No Quicksort? by Apocryphos · · Score: 2, Informative

      Like shit.

    8. Re:No Quicksort? by Anonymous Coward · · Score: 0

      No it's not. Otherwise Quicksort would not be O(n log n) and radix sort would not be O(n). Radix sort is sorting and then saying "well, I don't need to sort these bins, too."

    9. Re:No Quicksort? by Anonymous Coward · · Score: 0

      Well, almost.. In-place binary MSD-radix would be pretty close but standard quicksort uses data-dependent pivots.

    10. Re:No Quicksort? by llamafirst · · Score: 1

      What would an XKCDsort look like?

      I dunno what it would look like, but when they run the sound algorithm on it, it would sound like some awesome song from Guitar Hero.

  5. Shear Sort by jellomizer · · Score: 3, Insightful

    The Shear Sort is one of my favorite sorts out there. Although you will need an orchestra to play it.

    --
    If something is so important that you feel the need to post it on the internet... It probably isn't that important.
    1. Re:Shear Sort by Anonymous Coward · · Score: 0

      after reading about shear sort, I envision a waltz.
      http://everything2.com/title/shear+sort

    2. Re:Shear Sort by Abstrackt · · Score: 1

      The Shear Sort is one of my favorite sorts out there. Although you will need an orchestra to play it.

      And a wind tunnel.

      --
      They say a little knowledge is a dangerous thing, but it's not one half so bad as a lot of ignorance. - Terry Pratchett
  6. Excellent by schlick · · Score: 1

    That is awesome.

    --
    "It's because they're stupid, that's why. That's why everybody does everything." -Homer Simpson
    1. Re:Excellent by Anonymous Coward · · Score: 0

      It's sort of cool.

    2. Re:Excellent by Blakey+Rat · · Score: 0, Troll

      It was pretty awesome when I did it on my C-64 back in 1990 too. But I didn't have YouTube then, so I couldn't attention whore as effectively as modern programmers.

    3. Re:Excellent by Anonymous Coward · · Score: 0

      You're attention whoring right now, only problem is you've done shit all so stop raining on this guy's parade.

  7. Re:Everything is better with sound by Anonymous Coward · · Score: 0, Interesting

    Ted Bundy would disagree

  8. Just Play Popcorn by Hot Butter by Anonymous Coward · · Score: 1, Insightful

    It doesn't even matter if it matches the sorting. All sorting algorithms will benefit from the playing of Popcorn.

  9. Try it with people by twoshortplanks · · Score: 5, Funny
    It's always more fun to do this with real people (sort by height, for example). The London Perl Mongers tried this as a drinking game: You get enough people down the pub (or, in one this case, outside a bar in portugal during conference season) and apply booze. Then bubble sort them as a group (lots of shouting Stay! Switch!.) Add drinking penalties when people screw up the algorithm. You get the idea.

    There's a video on the internet somewhere. Free pint to the first person to find it.

    --
    -- Sorry, I can't think of anything funny to say here.
    1. Re:Try it with people by Inda · · Score: 1

      A variation we've played is to sort the line on age, but you're not allowed to say numbers and month names.

      --
      This post contains benzene, nitrosamines, formaldehyde and hydrogen cyanide.
    2. Re:Try it with people by siriuskase · · Score: 2, Funny

      No way, I don't want to stand near a guy who's only 5' 4". That's normal for women, but guys like that tend to have defective personalities. I like to stand near the tall guys.

      --
      If you must moderate, please moderate as irrelevent, not something bad, because I'm sure someone will find this interest
  10. Not boring, more interesting by decipher_saint · · Score: 1

    There was a dismissive comment recently modded down about being "easily amused" by the bleeps and bloops, well that may be so, but it sure adds flavor to the process.

    I can imagine how various sorting operations work in my head but I never thought about what they might sound like, and that makes them just a little more interesting. :-)

    --
    crazy dynamite monkey
    1. Re:Not boring, more interesting by amRadioHed · · Score: 1

      I never thought about what they might sound like either, but now that I know what they sound like I can't help but wonder what they might taste like. I'm betting quicksort tastes just like snozzberry.

      --
      We hope your rules and wisdom choke you / Now we are one in everlasting peace
    2. Re:Not boring, more interesting by Anonymous Coward · · Score: 0

      I'd wager bubble sort tastes like cactus needles and bee stingers!

  11. As a decided non-expert... by KingAlanI · · Score: 2, Interesting

    One thing this seems to show me (at least the video does)
    the rate of completion - how much is sorted by each point in the process
    the algorithms seem to all do that a bit differently; some have most of the work completed in the beginning, some in the end.
    Most seem to take one piece of data and plunk it right in order; the merge sort seems to be the only one with intermediate groupings.
    and there's one final pass to make sure the data's in order.

    I notice different sorting processes are appropriate for different RL sorting situations.

    --
    I listen to both RIAA and non-RIAA stuff if I like the music, tangential business/politics nonwithstanding.
    1. Re:As a decided non-expert... by pjt33 · · Score: 4, Informative

      The heap sort actually has intermediate structure. If you watch carefully you can see that it has two phases, the first much shorter than the second. However, the structure isn't as visibly obvious as for merge sort.

      If it had showed quicksort (I can't understand why it didn't) then you'd have seen some intermediate structure there too.

      I also noticed that the selection sort wasn't as good as it could be. It's more efficient to select the largest and the smallest unsorted values on each pass - you halve the number of passes, and on each pass you do 50% more work, so overall it's a 25% improvement.

  12. 60s/70s music by suso · · Score: 1

    A lot of them sound like something you'd hear at the beginning/end of some song from the 60s or 70s.

    1. Re:60s/70s music by LanMan04 · · Score: 1

      some song from the 60s or 70s.

      That only covers 20 years worth of music. Can you be more specific?

      http://en.wikipedia.org/wiki/Popcorn_(instrumental)

      --
      With the first link, the chain is forged.
    2. Re:60s/70s music by Tablizer · · Score: 1

      You mean kind of like the start of the 60's "Reflections" by the Supremes?:

      http://www.youtube.com/watch?v=yUuERNcQ8gk
         

  13. The sound of bubble sort by Anonymous Coward · · Score: 5, Funny

    That's strange. When I listen to the sound of bubble sort all I hear is one of my college professors threatening to hunt me down and kill me in my sleep if I ever use it.

    1. Re:The sound of bubble sort by MrMe · · Score: 1, Funny

      That's strange. When I listen to the sound of bubble sort all I hear is one of my college professors threatening to hunt me down and kill me in my sleep if I ever use it.

      I just hear my bong.

    2. Re:The sound of bubble sort by Anonymous Coward · · Score: 2, Informative

      then your profs are kinda dumb, there are plenty of times when its acceptable to use bubble sort....

      suppose you are on an embedded device, and you know that your inputs will always be limited by some factor, bubble sort also has rather good cache performance

    3. Re:The sound of bubble sort by lewiscr · · Score: 1

      Bubble sort does have it's uses; if you know the array is <= 3 elements, Bubble Sort wins.

    4. Re:The sound of bubble sort by jfengel · · Score: 2, Interesting

      And that's not uncommon. There are plenty of circumstances where you may have a large number of short lists floating around. Say, a list of a person's children, which will be less than 4 in 99% of cases and even the extreme cases aren't going to kill you. There may be many instances of the list, but each will be small.

      Sorting those lists via some O(n^2) sort is lower overhead than building up fancy data structures. Especially if you're building the lists incrementally, such as via an insertion sort (much like an incremental bubble sort).

    5. Re:The sound of bubble sort by Joce640k · · Score: 1

      Yep, I've seen optimized implementations of quicksort which drop down to bubble sort when there's only three or four elements in the current subdivision.

      PS: The one in the video could easily be optimized to go twice as fast and would beat some of the others if you did.

      --
      No sig today...
    6. Re:The sound of bubble sort by Anonymous Coward · · Score: 0

      It also parallelizes to O(N) time if you happen to have N processors.

    7. Re:The sound of bubble sort by sconeu · · Score: 1

      The bubble sort one actually did sound kind of bubbly.

      --
      General Relativity: Space-time tells matter where to go; Matter tells space-time what shape to be.
    8. Re:The sound of bubble sort by ImprovOmega · · Score: 1

      This is why I always liked Heapsort. In place sorting in an array (O(n) space) and optimal time complexity (O(n*lg(n)) steps). If you bother to learn Heapsort well, you don't really *need* any other sorting algorithm.

  14. Could be Better by Evets · · Score: 1

    I'm not a big fan of these sounds, but I like the idea.

    Merge Sort - traffic sound
    Bubble Sort - blowing bubble sound from bubble bobble
    Insert Sort - coin slot
    Select sort - crain game sounds
    Gnome Sort - 7 dwarfs singing Hi-Ho, Hi-Ho

    At least that way you can associate sounds with different algorithm types and remember what they are.

  15. Sounds for Dr. Who by Anonymous Coward · · Score: 0

    Any one see this as some sound files for the BBC Dr. Who Series.

  16. Hardly new by by+(1706743) · · Score: 1

    My CS lecturer prepared a number of these for an intro CS course. I took the class back in '06-'07, but IIRC the videos were taken from Mac OS X. That said, it is pretty neat.

    1. Re:Hardly new by by+(1706743) · · Score: 1

      ...Mac OS X.

      Gah, meant Mac OS < X

  17. Diagnostics by PPH · · Score: 4, Interesting

    One interesting application of such audible/visual representations could be for diagnostic reasons.There are numerous cases where experienced observers can spot patterns or anomalies in patterns that machine algorithms have trouble with.

    One example I was involved in years ago at Boeing was a tool for diagnosing a large switch matrix used in a piece of automated test equipment. Each output could be tied to a high, low or open signal, driven from a controller over an HPIB bus. Failure modes included not only an output stuck high, low or open, but address bus problems where some lines would cause passive failures or activate more than one pin. After watching a poor engineer go through a suspect matrix panel for over a day, entering a command on the bus, finding the pin on a patch panel, sticking a voltmeter on it, over and over a few thousand times, we came up with a solution. Bi-colored LEDs wired to a patch panel and a program to exercise the matrix with a series of address patterns. An observer could spot a single bad switch or a hung address bus line in a few seconds just by looking for an anomaly in a couple of checkerboard and other patterns.

    --
    Have gnu, will travel.
  18. should be marked NSFW by Anonymous Coward · · Score: 0

    because i just got off to that geek pr0n

  19. Clown Sort by quatin · · Score: 1

    My favorite sort. Randomly arrange items until they are in order. Would the appropriate music be some type of carnival melody?

    1. Re:Clown Sort by maxwell+demon · · Score: 2, Informative

      I know this as bogosort. Wikipedia also mentions random sort, shotgun sort and monkey sort as alternative names, but not clown sort. Also a Google search for "clown sort" doesn't seem to give sorting algorithm results, not even if I add algorithm as additional search term.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    2. Re:Clown Sort by operagost · · Score: 1

      They probably mean bozo sort. You take two random items and switch them.

      --

      Gamingmuseum.com: Give your 3D accelerator a rest.
  20. Bugged bubble sort? by Anaerin · · Score: 2, Interesting

    The bubble sort used here is kinda bogus. It iterates over the whole set on every pass, which it doesn't need to. It only needs to go over dataset-(pass-1) items. I have a feeling this will change the "sound" of the bubble sort in this example.

    1. Re:Bugged bubble sort? by Anonymous Coward · · Score: 2, Informative

      That optimization doesn't change the run-time complexity of the algorithm, it's still O(n^2). Usually bubble sort is taught without the optimization and once the student understands, you point out that particular optimization or try to get them to figure it out on their own.

    2. Re:Bugged bubble sort? by BitterOak · · Score: 1

      That optimization doesn't change the run-time complexity of the algorithm, it's still O(n^2). Usually bubble sort is taught without the optimization and once the student understands, you point out that particular optimization or try to get them to figure it out on their own.

      I haven't yet run across a comp. sci. text that describes the bubble sort without the "optimization". I've always thought it was an intrinsic part of the bubble sort algorithm.

      --
      If I can be modded down for being a troll, can I be modded up for being an orc, or a balrog?
    3. Re:Bugged bubble sort? by Anonymous Coward · · Score: 0

      It partly depends on whether comparing or copying takes the bulk of the time. If comparing is cheap and copying is expensive, you don’t really care about the optimization. In fact you might actually be led to erroneously believe that the search did implement the optimization when it really didn’t.

  21. What Fun! by PocariSweat1991 · · Score: 1

    The Selection Sort's soundtrack was quite fun!

    It feels like your head is going to explode at the end, and the final pass is the sound of brain matter splattering across the pages of your algorithms textbook.

  22. Visual Aids by Anonymous Coward · · Score: 1, Interesting

    I found http://www.sorting-algorithms.com/ to be useful for looking at how sorting works, too.

  23. Also fun: porttwiddle by Anonymous Coward · · Score: 1, Interesting

    http://wolfbell.com/projects/index.html - Porttwiddle is an add-on module to a one-disk linux router project that will play sounds of different frequency depending on the port number. You'll never miss a portscan again! ;-)

  24. Sorting is fun by operagost · · Score: 1

    I sorta like it.

    --

    Gamingmuseum.com: Give your 3D accelerator a rest.
    1. Re:Sorting is fun by kramulous · · Score: 1

      [quote]I sorta like it.[/quote]
      I have mod points but couldn't find 'dad joke'

      --
      .
  25. Which sounds best? by kabloom · · Score: 1

    They should bring back the Slashdot poll to discuss which of these sorting algorithms sounds best. (IMO, Insertion sort, bubble sort, and Heapsort sound coolest.)

    1. Re:Which sounds best? by treeves · · Score: 1

      I liked selection sort the best. Musically, the "piece" constantly seems to accelerate leading to a pleasing conclusion. But merge sort was a more complex piece.

      --
      ...the future crusty old bastards are already drinking the Kool-Aid.
  26. Very Old Idea by canajin56 · · Score: 1

    The sounds aren't quite the same, but Quick Basic for MS DOS had a program in the Examples folder that does almost exactly this. Generates random data and shows various sorting techniques on it visually, playing a different tone for each comparison made. Not as much data (since it had to graph it in 320x200), much slower in a 286, and sound was done by internal speaker, but same idea at least.

    --
    ASCII stupid question, get a stupid ANSI
  27. sort video memory by Anonymous Coward · · Score: 0

    A tutor once filled text mode video memory (DOS days, no memory protection) with the solid block character in random colours, then sorted said video memory with bubble sort, heap sort, shell sort and quick sort. In other words, the coloured blocks sorted themselves on screen. Remarkably effective demonstration of the relative speeds and of how the algorithms work.

  28. Sorting is a waste of time by mmaniaci · · Score: 1

    Meh, sorting should be covered in about 2 hours in any programming course. I spent an entire quarter on sorting back in college and I still to this day cannot see the point of repeating the same exercise over and over again, just with a different sorting algo. But perhaps my professor was just retarded (that was the general consensus between the students anyway).

    WTB New slashdot CSS/JavaScript programmer. The current one really blows.

    1. Re:Sorting is a waste of time by mea37 · · Score: 5, Insightful

      If you think all that time examining sorting algorithms was intended to teach you about sorting, then you indeed missed the point. Programming courses spend a lot of time on sorting because it is a common task that can be easily understood, but for which there are a lot of different algorithms with very different performance characteristics. The point is to teach algorithm analysis skills.

      Judging from the quality of code I encounter regularly, though, you're far from alone in failing to pick up that lesson.

    2. Re:Sorting is a waste of time by rrohbeck · · Score: 1

      Exactly. The only time I ever looked at sorting algorithms was in university. For the last 20+ years, all I ever did was call some sort() or qsort() library function.
      Considering whether to apply a Schwartzian Transform was probably the most I ever thought about sorting.

    3. Re:Sorting is a waste of time by clone53421 · · Score: 1

      The point is to teach algorithm analysis skills.

      Well, that, and to teach that their performance isn’t the only metric that you can judge them by... for instance, the “best” (fastest) sorting methods also tend to be the most inefficient in terms of how much extra memory they need. If you swap elements with XOR, a bubble sort only requires 1 extra bit to tell it when it’s finished.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    4. Re:Sorting is a waste of time by ImprovOmega · · Score: 1

      Heapsort is optimal in time and space. It can be mildly complicated to code if you're not careful, but the whole thing can be done in one function without recursion, so you don't even have stack overhead with it. Of course, if your sorting needs are wildly complicated (like, you're a developer for Oracle or something) then others may make more sense. But for your average run-of-the-mill array sorting, Heapsort should be all you ever really need.

  29. sorting rules by bhcompy · · Score: 1

    Sorting may be boring, but it is an awesome way to really dive in to a language(at least c++).

  30. Boring?? by Tetsujin · · Score: 1

    I read Knuth for fun... I don't get this notion of algorithms being "boring"...

    --
    Bow-ties are cool.
  31. Fairly dry? by sgraar · · Score: 1

    What do you mean it's fairly dry? Sorts are awesome!

    Respect the sorting algorithms!

    1. Re:Fairly dry? by Anonymous Coward · · Score: 0

      My favorite (and most memorable) part of my high-school programming classes was learning the sorting algos.

  32. Sorting real objects by spaceyhackerlady · · Score: 3, Interesting

    As an undergrad I worked in the university library to earn a bit of spending money, and one of my tasks was sorting books to put them back on the shelves. My colleagues used selection sort. I didn't.

    I did a first pass through the books. Two piles, typically A-L, M-Z. Then a second pass, A-D, E-L, M-R, S-Z. And so on, until the piles were small enough I could go through them and put them on the shelf in order.

    How many people do you know who actually use quicksort to sort real objects?

    ...laura

    1. Re:Sorting real objects by SpeedBump0619 · · Score: 1

      Well, to be pedantic, that's not *strictly* quicksort. It's a two bin radix sort. The only difference, of course, is that in quicksort you pick your pivot based on some item(s) in your set, and in radix you select the boundary based on properties of the data distribution. I only mention it because I *have* seen something that uses radix sort on physical objects: an old punch card sorter.

    2. Re:Sorting real objects by rrohbeck · · Score: 1

      I always used a variation of the aptly name Library Sort: Throw all the books on the floor and then put them roughly in the right position on the shelf, leaving gaps. After all, you have almost infinite scratch space.

    3. Re:Sorting real objects by clone53421 · · Score: 1

      I always do an insertion sort until it starts getting inefficient (pretty soon usually) then abandon my sorted stack and start a new one. Once I have sorted everything into small sorted stacks, I merge sort them two at a time to get larger sorted stacks, then repeat until I have only one sorted pile.

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
    4. Re:Sorting real objects by Anonymous Coward · · Score: 0

      i'm going to sleep soundly tonight since learning i've been quicksorting all my life :-)

    5. Re:Sorting real objects by LucasBrown · · Score: 1

      I know 0; however, I use mergesort (bottom-up variety) with great regularity for arranging cards/books/etc.

      --
      5621*2^524509+1 is prime. Find more of them - join PrimeGrid!
    6. Re:Sorting real objects by Pennidren · · Score: 1

      I thought you were going to describe Library Sort as it always seemed to me: Throw all of the books on the floor and then jam them on the shelf with no gaps and plenty of books from incorrect sections randomly scattered throughout. Oh, and sprinkle horizontal books liberally on top.

    7. Re:Sorting real objects by theazreal · · Score: 1

      I also did this when I worked in the library in college. Although it's true that I took some programing classes, I think this is just common sense. Most of my student coworkers were social science or liberal arts majors, and as far as I saw, they all did the same thing.

      I think it's more about whether your fellow students have any sense than whether or not they know about quicksort.

    8. Re:Sorting real objects by Anonymous Coward · · Score: 0

      well, to be pedantic. that's not *strictly* two bin radix sort either!
      it's a merge sort, no?

      but you're right about the old punch cards. those can be sorted quickly with radix sort.

  33. What about Random Sort by ookabooka · · Score: 1

    What about random sort, where you swap 2 random values and test to see if it is sorted. I assume it would sound like static, probably white noise (as opposed to pink noise).

    --
    If you are about to mod me down, keep in mind that this post was most likely sarcastic.
    1. Re:What about Random Sort by clone53421 · · Score: 1

      I would optimize that by only swapping the values if they’re out of order:

      <html>
      <body>
      <canvas id="paintbox" height=480 width=640 />

      <script>
      function sorted(a) {
          for (var i = 0; i < a.length;) if (a[i] > a[++ i]) return false;
          return true;
      }

      function sort_values() {
          if (!sorted(a)) {
              var i = (Math.random() * (a.length + 1)), j = (Math.random() * a.length), t;

              if (j >= i) j ++;
              else { i ^= j; j ^= i; i ^= j; }

              if (a[i] > a[j]) {
                  t = a[i];
                  a[i] = a[j];
                  a[j] = t;

                  canvas.clearRect(i, 0, 1, 480);
                  canvas.fillRect(i, 480 - a[i], 1, a[i]);
                  canvas.clearRect(j, 0, 1, 480);
                  canvas.fillRect(j, 480 - a[j], 1, a[j]);
              }

              var t = setTimeout("sort_values();", 10);
          }
      }

      var a = new Array();

      try {
          var canvas = document.getElementById("paintbox").getContext("2d");

          for (var i = 0; i < 640; i ++) a[i] = Math.floor(i / 640 * 480);
          for (var i = a.length - 1; i > 0; i --) {
              var j = Math.floor(Math.random() * (i + 1));
              a[i] ^= a[j]; a[j] ^= a[i]; a[i] ^= a[j];

              canvas.fillRect(i, 480 - a[i], 1, a[i]);
          }

          var t = setTimeout("sort_values();", 10);

      } catch (e) {
          alert("Get a better browser!");
      }
      </script>
      </body>
      </html>

      (Bonus points if you knew what i ^= j; j ^= i; i ^= j; does without thinking about it too hard. Those are bitwise XOR operations, in case anyone didn’t know.)

      --
      Alexander Peter Kristopeit bought his basement from his mommy for one dollar.
  34. Really? by Radtoo · · Score: 1
    I do not think the sound adds anything, myself. The visuals could be helpful if played more slowly, but the sound? It does not help me, and as used in TFA, it is even an annoying noise.

    Actual code and performance analysis shouldn't be boring or "dry" to someone who aspires to be a computer scientist or specifically a programmer, especially not the first time they learn about it...

    1. Re:Really? by pclminion · · Score: 1

      I do not think the sound adds anything, myself. The visuals could be helpful if played more slowly, but the sound? It does not help me, and as used in TFA, it is even an annoying noise.

      An old boss of mine used to work on a large computer which was used to control the activities inside a sawmill. It was made up of several thousand magnetic reed relays to perform the logic. The program itself was keyed into the system via about 1000 throw switches. The entire machine was devoid of silicon. This was pretty "old school." When the "code" was updated and a bug was introduced, he was often able to diagnose the bug by listening to the buzzing, clacking and whirring of the relay switches opening and closing. Stuck in an infinite loop somewhere? That made a "bzzz chicka chicka brr brr bzzz chicka chicka brr brr" sound. Is bit 6 of the program counter register stuck at zero due to a wiring fault? Why, it goes "whacka chunka whacka chunka whacka chunka..." After months of experience, he was able to characterize the internal state of the control program simply by listening to the sound of the machine. Don't discount the value of all possible input modalities when trying to understand how something works.

    2. Re:Really? by Radtoo · · Score: 1

      Your boss taking months to "get used" to the sound is important here, and the fact that he was using it to diagnose problems, not for learning how the machine works conceptually.

      Sure, anyone can probably very easily tell a badly broken engine (no sound, heavy thumps, clacking, croaking etc) from a working one - even after experiencing a working one only once. But that is all - you do not learn at all how an engine works from hearing it, nor can you omit the prior learning.

      We use our spatially accurate senses (sight, touch) and communication in abstract terms -language- to learn about things conceptually, not hearing or taste or heat perception. The spatially inaccurate senses however are very good at detecting irregularities and so on - but that is all based on experience not learned or conceptualized with these senses.

  35. Listening to music by EkriirkE · · Score: 1

    I was listening to some dance/trance music. I though I had a problem with my speakers playing the video because I didn't notice any new sounds :o

    --
    from 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
    to 45 2F 6E 40 3C DF 10 71 4E 41 DF AA 25 7D 31 3F
  36. Possibly the easiest C sort for arbitrary types by Flector · · Score: 0

    Still possibly the easiest (C++) sort for arbitrary types:


    #include <vector>
    #include <algorithm>
    #include <functional>

    class my_type
    { public:
    int item_data;
    };

    bool isless_my_vector (const my_type ref1, const my_type ref2)
    { return ref1.item_data < ref2.item_data ? true : false; };

    int main ()
    {
    std::vector some_vector;

    // populate some_vector
    my_type item;
    item.item_data = 5;
    some_vector.push_back (item);
    item.item_data = 10;
    some_vector.push_back (item);

    std::sort (some_vector.begin(), some_vector.end(), std::ptr_fun (isless_my_vector));

    for (std::vector::iterator iter = some_vector.begin(); iter != some_vector.end(); iter++)
    {
    item = *iter;
    // do something with item
    }
    return 0;

    }


    It's more efficient if the vectors holds pointers instead of data.

    1. Re:Possibly the easiest C sort for arbitrary types by kramulous · · Score: 1

      It's more efficient if the vectors holds pointers instead of data.

      It's more efficient if you don't use std::vector.

      --
      .
  37. Boring? by StikyPad · · Score: 1

    Sorting may be boring to implement repeatedly (tedium by definition), but I found learning the various standard sorting algorithms to be pretty interesting, and a great practical introduction to pointers.

    Programming is first and foremost about problem solving, regardless of whether you're creating a game or a spreadsheet, and sorting is a common problem. If you find learning (and discovering) how to solve problems effectively and efficiently to be boring, then you're probably pursuing the wrong line of work.

  38. If the implementation was written in C by broknstrngz · · Score: 1

    the authors should listen to Franz Schubert's Symphony Number 9.

  39. Where are the llamas? by knarf · · Score: 1

    Nice vids but where are the llamas?

    For all you young whippersnappers: these sounds resemble the noises emanating from a series of C=64 games by Jeff 'Yak' Minter, one of the better known software developers from the 80's.

    --
    --frank[at]unternet.org
  40. random sort by Flector · · Score: 0

    random sort:

    seed random
    create vector of pointers to data, with rand variable
    std::sort() by rand member

  41. you don't give this guy enough credit by Anonymous Coward · · Score: 0

    For me, he's a legend. Technology is full of wonder and because of education and corruption, people don't really see or experience this kind of thing nearly enough. This is way better than anything else I've seen. A college mate of mine did a project in Ireland on visualizing the main algorithms but this is erm heeps ..ahem better.
    The key to human education is in our senses - all of them!! even feelin, emotions can be used to understand technical concepts. You may not know it but this is at the fringe of technology. We poor, forsaken humans aren't allowed access to it for the most part, but in an ideal world, visual, and acoustic aids can be used in this manner to learn algorithms of some complexity.

    The open source developers behind Apache, PHP, Mozilla etc. are vitally important to us but this guy and people like him are the future of education if there is to be one.

    And note, how elegantly this ties in with cellular automata / game of life etc. They're really one and the same to those of us who are not automaton's and can see that.

    Wolfram is on the right track.

    AWESOME

  42. the gnome sort by Anonymous Coward · · Score: 0

    makes me think of an old lady hoovering a floor on speed!

  43. Boring IF you add sound. by Anonymous Coward · · Score: 0

    Seriously? That many people thought this was neat? The sounds are totally annoying. That's why it's video and not audio, the video is sort-of neat as we can see what's happening. The audio, with or without the video only detracts from the ambient noise anywhere in the world.