Counting Sort in java

In this post, we will learn how to implement Counting Sort in java.
Sorting Algorithm in java.

Counting Sort Algorithm

Counting Sort Algorithm is an integer-based algorithm, non-comparison, and linear sorting algorithm. Counting sort algorithm sorts the elements in an array in a specific range. It is based on keys between the specific range.
Counting sort calculates the number of occurrences of objects and stores its key values. Then by adding the previous key elements, a new array is formed.

Time Complexity of Counting Sort:

Best case:  0(n+k)
Average case:  0(n+k)
Worst case:  0(n+k)

Implementation of Counting sort in java

The output of Counting sort algorithm in java:

Also, learn:
Bubble Sort
Heap Sort
Insertion Sort
Quick Sort
Merge Sort
shell Sort