As we learned from the article A lower approximation of the sorting problem complexity we cannot sort with a better time complexity than O(n log n). This limitation applies to the decision tree, which must be covered by mutual comparison of the items. However, what if we could sort the items without comparing them? Would we be able to sort the array in linear time? It sounds crazy, but it's totally possible. There are multiple sorting algorithms based on this principle and Counting sort is one of them.
This algorithm only sorts integers, which isn't necessarily a problem because it's what we usually sort. For other values, we can simply convert the data into integers (e.g. multiply the numbers with 2 decimal places by one hundred, sort them, and then divide them again). The sorting part is done using an auxiliary array which is called the counting array, sometimes also the indexing array. The counting array should be as long as
...End of the preview...
You've come here and that's great! We believe that the first lessons showed you something new and useful
Do you want to continue the course? Go to the premium section.
Warning, by buying just this lesson you'll lose the limited 15% discount for the package of all the lessons.
- Unlimited and permanent access to individual lessons.
- High quality IT knowledge.
- Skills to help you get your dream and well-paid job.
Requested article covers this content:
This article is about Counting sort, which is able to sort numbers according to their value in linear time. Source codes for languages Java,C#,Delphi,Ruby.
You gain points by supporting our network. This is done by sending a helpful amount of money to support the site, or by creating content for the network.