What is the average time complexity of counting sort?

Phương Linh

New member
What is the average time complexity of counting sort?
A. O(n)
B. O(n+k) k=range of input
C. O(n$^{2}$)
D. O(n log n)
 
Answer: b
Explanation: Time complexity of counting sort is O(n+k) as counting the occurrence of each element in the input range takes k time and then finding the correct index value of each element in the sorted array takes n time.
 

Tìm kiếm

Back
Top