edited on 2012-10-09

Sorting Algorithms

Several months ago I’ve enrolled in one of Coursera’s awesome classes, Algorithms: Design and Analysis from Tim Roughgarden. I think, most of you know about these online classes from Coursera and Udacity, if you don’t, I strongly advise you to take a look. I’m sure you will find a class that suits you. Anyway, this class was my third online class and I didn’t manage to finish any of them yet, nevertheless I’ve learned so much from them.

As the title says, this post is about sorting algorithms which is the first subject of Algorithms class. I’m not really sure if sorting algorithms can be classified as artificial intelligence but I have noticed that I know so little about these algorithms and I wanted to write a post about them.

I think there is no need to explain each of the algorithms even briefly because there is a lot of information on the internet and these algorithms are explained way better than I can do. So, I created an application and you can download the source code as usual, with it you can compare the performances of these algorithms.

In the application, I’ve included some of the most common sorting algorithms which are:

and I have also included 4 different kinds of data sets. If we assume that a data set contains n elements, then each data set type is generated as follows:

Actually, making a fair comparison of sorting algorithms is not quite possible with ActionScript because Flash Player is working on too many layers, nevertheless it will help you to get the main idea. For example it helped me to understand that a sorting algorithm, let’s say quicksort, should be optimized for the expected data set. If you expect that your data set will be reversed sorted then the pivot should be chosen from the middle of the subset, otherwise the first or the last element of the subset works better.

I think, this time I’ve come up with an application which explains itself but just for the sake of this post, here are the instructions on how to use it.


All of the grey squares are buttons and all of the green squares are sorting nodes

And last but not least, I want to share some resources about sorting algorithms, they helped me a lot in writing this post.

If you think that this article is wrong or missing, or maybe you have a question, please feel free to send me a message.

download source files