Counting Sort
Let's learn the counting sort algorithm.
We'll cover the following...
Overview
Counting sort is a non-comparison-based sorting algorithm based on keys between a specific range, that works by sorting the elements of an array by counting the number of occurrences of each distinct element in the array.An auxiliary array is used, and the count is stored in it. Sorting is done on it by mapping the count as an index of the auxiliary array.
Algorithm
Given an array
arr
, calculate the maximum value.Create an auxiliary array of the maximum value
length and initialize it with ...