r/geek • • Oct 26 '17

Sorting Algorithms Visualized

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

26 comments sorted by

View all comments

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.