We have seen sorting algorithms in the previous article. In this article, we are going to discuss the Counting Sort Algorithm.

When comparing elements, no sorting algorithm can sort n elements in less than ** O(n log n)** time. Fortunately, if we know some information about the elements ahead of time, we can sort them in other ways. Assume we are asked to sort

A counting sort (ultra sort or math sort) is a sorting algorithm that sorts an array’s elements by calculating the number of occurrences of each distinct array element. The count is stored in an auxiliary array, and sorting is accomplished by mapping the count to an index in the auxiliary array.

Counting sort uses the range ** (k)** of the numbers in the array

There are **three phases** in this algorithm.

- Counting the Elements
- Aggregating the Histogram
- Writing Back Sorted Objects

The array below must be sorted.

Find the largest element (let it be ** max**) in the given array. Create an array of length

The Selection Sort algorithm sorts an array by looking for the smallest item and moving it to the front of the list. That’s really all you…

As [Bubble Sort](https://www.interviewbit.com/tutorial/bubble-sort/ "Bubble Sort") represents the basic foundations of sorting, we've tried to demystify this sorting algorithm.

Heap Sort Algorithm Visually Explained - Now that we know how to create a max-heap, we’ll move into sorting an array of values using heap sort. To sort the array using heap sort…

Speaking about sorting algorithms, one should always remember: there is more than one approach. Last time we talked about Insertion Sort and worked with one unsorted array. This time we’re going to try a different approach and more complicated pattern — Merge Sort. Our starter pack is two sorted arrays, our task is to combine them into one sorted array.

Topological Sorting Visually Explained - Topological sorting is the result you get when you sort the tree in order of decreasing finishing times. What this means is that you run…