Search⌘ K
AI Features

Counting Sort

Explore how counting sort operates as a non-comparison-based sorting algorithm by counting and indexing element frequencies. Learn its implementation steps and analyze its time and space efficiency to grasp sorting for elements within a specific range.

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 +1+1 length and initialize it with  ...