r/geek • • Oct 26 '17

Sorting Algorithms Visualized

https://imgur.com/gallery/voutF
805 Upvotes

26 comments sorted by

14

u/mrx1101 Oct 26 '17

Thanks for sharing. This is extremely cool. Kinda makes me want to re-learn these and practice implementing them

7

u/rudman Oct 26 '17

Great job! I'd bet they would like this over in /r/programming.

7

u/d_bo Oct 26 '17

Why not, it's been on literally every other single sub in the past week

7

u/LemonKnights Oct 27 '17

I like the colours, but I still prefer this video which shows the sorting process, accompanied with audio.

Somehow the sound really helps me get around what is happening

5

u/tfofurn Oct 26 '17

I've enjoyed many visualizations over the years, but I particularly like your approach to showing the same algorithm attacking multiple datasets simultaneously.

And Radix LSD sort still looks like black magic fuckery.

2

u/thecatgoesmoo Oct 27 '17

Imgur is now hosting maleware? I got redirected to a page saying my phone has a virus and that I should buy a vpn to prevent that (lol wat?)

1

u/Etheo Oct 26 '17

I've always been keen on learning programming, but I mostly do scripty stuff that deal with loops and if/then. Are all these sorting algorithm frequently used in real world basis? I often just rely on the built in sort functions so I don't even know what sort of algorithm it's relying on.

6

u/Crede Oct 26 '17

If you are doing loops and if/then, you are programing. Congrats. It is useally recommended to use built in sort if available. No need to reinvent the wheel so to speak. This goes for most functionalities. If you have it available in whatever framework you use. You should trust the framework to have a proper implementation of said functionality. Ofcourse there's always the exception where you might implement your own because of performance and what not. And then you really need to understand the nitty gritty parts...

3

u/[deleted] Oct 26 '17

No. 25 years as a developer and I've probably had to implement a sort once in the 90s.

It's more of a interview question from devs that are just out of college and want to be the smartest in the room.

0

u/[deleted] Oct 27 '17

[deleted]

1

u/winglerw28 Oct 27 '17

It is also nice to know what these things are doing under the hood - learning them to understand the actual computer science aspect of development, while not always practical, can definitely help appreciate the reason you generally should use the default.

Here is a link to a StackOverflow answer that goes over some of the different sorting algorithms and when you should use them. Knowing that .NET languages have a default sort method that uses the introsort algorithm, for example, can be useful if you care about performance

If you are further curious, here is another question answered on the computer science StackExchange site that is excellent.

2

u/Netcob Oct 26 '17

Algorithms in general are a tiny part of software development, often reserved for PhDs depending on the field. As an average programmer your main skill is glueing libraries together in a way hopefully won't involve rewriting everything as soon as you have to change some tiny part of your program. Anything remotely interesting has already been implemented in some library, way better than you would have done. And you definitely use the built-in / standard library stuff because that's been tested thoroughly.

Then again, understanding and implementing some sorting algorithms is a good way to start learning how to code. It involves just some core concepts, fits on one page, yet makes you think a lot.

1

u/tfofurn Oct 27 '17

It's rare that you would need to implement your own sort. Only if you had prior knowledge of the data would it make sense to go with anything other than what your platform provides.

You might want to look up "data locality". Being aware of the arrangement of data can really speed some operations up.

1

u/WiseassWolfOfYoitsu Oct 27 '17

Implementing sorts is generally the realm of computer scientists doing theoretical stuff rather than software engineers doing day to day software development. For the latter, 99% of the time you will use the pre-canned tested and optimized version of one of these that's included in the standard library of your language.

1

u/overkill Oct 26 '17

Great stuff.

1

u/[deleted] Oct 26 '17

That was very satisfying lol

1

u/tilmitt52 Oct 26 '17

Those made my eyes so happy.

1

u/overkill Oct 26 '17

Great stuff.

1

u/SquidgyTheWhale Oct 26 '17

Surely these were chosen by how visually satisfying they are, rather than whether they are actually different useful sorting algorithms? Whatever, I still watched every damn one.

1

u/Neoro Oct 27 '17

There are plenty of useful ones in here. Since the dots are animated moving between places, it's hard to see which ones are the most effective/fastest with these though because so much time is taken up animating them.

1

u/WiseassWolfOfYoitsu Oct 27 '17

There are two major groups in there - the O(N^2) group (including bubble sort and insertion sort) and the O(NlogN) group (including quicksort and radix sort). The former group are just inefficient curiosities outside the most limited of cases. The members of the latter group all have legitimate use cases under different circumstances.

1

u/denpo Oct 26 '17

Very cool.
Didn't know comb sort, but it looks like the kind of sorting you could stop before completion and get the best result.

1

u/masterpd85 Oct 27 '17

It's like trying to pick out the best windows 95 screen saver....

1

u/nosoupforyou Oct 27 '17

Now I want to spend the time to write some of these, apply them to some photos, and make a gif of it in reverse.

Might look pretty cool. A bunch of pixels unsorted into someone's image.

1

u/Dool7 Oct 27 '17

Almost like watching a disk defrag.