- Related Questions & Answers
- Selected Reading
Sorting Algorithm Algorithms Data Structure Counting sort is a stable sorting technique, which is used to sort objects according to the keys that are small numbers. It counts the number of keys whose key values are same.
Counting sort is a stable sorting technique, which is used to sort objects according to the keys that are small numbers. It counts the number of keys whose key values are same. This sorting technique is effective when the difference between different keys are not so big, otherwise, it can increase the space complexity.
The complexity of counting Sort Technique
- Time Complexity: O(n+r)
- Space Complexity: O(n+r)
Input and Output
Algorithm
Input: An array of data, and the total number in the array
Output: The sorted Array
Source Code (C++)
Output
- Related Questions & Answers
- Selected Reading
Counting sort is a stable sorting technique, which is used to sort objects according the keys that are small numbers. It counts the number of keys whose key values are same. This sorting technique is efficient when difference between different keys are not so big, otherwise it can increase the space complexity.
The complexity of counting Sort Technique
- Time Complexity: O(n+r)
- Space Complexity: O(n+r)
Input − A list of unsorted data: 2 5 6 2 3 10 3 6 7 8
Output − Array after Sorting: 2 2 3 3 5 6 6 7 8 10
Algorithm
countingSort(array, size)
Input: An array of data, and the total number in the array
Output: The sorted Array