DEV Community

Cover image for 8 must-know sorting algorithms

8 must-know sorting algorithms

Mangabo Kolawole on October 18, 2020

In this post, I am going to show you common sorting algorithms and provide their implementation in python. If you are a programmer or if you have a...
Collapse
 
aminmansuri profile image
hidden_dude

Why is BubbleSort considered so important? I'd say it's the last failed algorithm you should know.

Important ones would be:

  1. InsertionSort and it's efficient variations ShellSort and HeapSort. Because it has a O(N) best case behavior (when already sorted).

  2. QuickSort, because in it's randomized version illustrates the power of random, and it's simplicity and raw speed.

  3. MergeSort because of it's stability and usefulness in parallel algorithms, distributed algorithms, and databases (ie. Merge join)

  4. RadixSoft because it's not a comparison algorithm and takes time O(n lg u) (which is MUCH faster than Quicksort). Van Embde Boas if you want to get really performant with these concepts with time O(n lg lg u).

  5. BitonicSort because it's a basic parallel sorting algorithm and also used in the more sophisticated theoretical efficient sorting algorithms.

  6. TimSort: because it's the one that's actually implemented in Python and Java so it's a good case study of a real world sorting algorithm.

But I think you can safely forget BubbleSort ever existed. I think SelectionSort is way more intuitive anyway.

Collapse
 
muhammadmuzammilqadri profile image
Muhammad Muzammil

Actually, BubbleSort IS an important sort, and anybody calling him or herself a Software engineer needs to understand how it works.

Reason? Well, you can't understand the concept of Light completely without understanding what the Darkness is. I know it's toooo dramatic but believe me, you need to know what bad algorithms are in order to understand the good ones.

Collapse
 
aminmansuri profile image
hidden_dude

sure.. though selection sort is sufficient to represent naive sorting..
but I'll grant that you have a point

Collapse
 
koladev profile image
Mangabo Kolawole

Thanks for the answer. I will look to add TimSort to the article.

Collapse
 
aminmansuri profile image
hidden_dude

sorry I didn't mean to sound so dogmatic..

but wanted to share an alternative set of "essential" algorithms

Collapse
 
tomc profile image
tomc

2 comments.

First, I would introduce Mergesort before Quicksort. While Quicksort is of greater general importance, mergesort is a good introduction to the divide and conquer type of strategy. Since I would group quicksort as a div&conq algorithm, it makes sense to start with a "baseline" of mergesort before venturing into more complicated examples with partitions, etc.

On the "other" algorithms request, you could add Radix sort to the list, possibly as a augmentation to the bucket sort. One other algorithm worth mentioning might be Timsort given its (a) advanced nature and (b) ties to Python.

Collapse
 
the-real-i9 profile image
i9

😀 This is awesome!

Collapse
 
koladev profile image
Mangabo Kolawole

Thanks a lot! :)

Collapse
 
quochungphp profile image
quochungphp

Thanks so. It's very nice

Collapse
 
derricksherrill profile image
Derrick Sherrill

Awesome post, fantastic job!

Collapse
 
koladev profile image
Mangabo Kolawole

Thanks Derrick!

Collapse
 
phoebusg profile image
Phoebus Giannopoulos

Excellent review, haven't looked at these since programming class (JAVA), nice to see Python code for each.. Keep it up!

Collapse
 
muhammadmuzammilqadri profile image
Muhammad Muzammil

Nice article. Though it could be much much and much better if you had added the complete gifs. As you know if a picture is worth a thousand words then a good gif is certainly worth a million