What is the auxiliary space requirement of counting sort?

Quốc Ân

New member
What is the auxiliary space requirement of counting sort?
A. O(1)
B. O(n)
C. O(log n)
D. O(n+k) k=range of input
 
Answer: d
Explanation: Counting sort uses two extra arrays to get the input array sorted. First array is required to store the count of all the elements which fall in the range of input data elements, so its size is k. The second array is required to store the input elements in sorted manner, so its size is n. Thus overall auxiliary space required becomes O(n+k).
 

Tìm kiếm

Back
Top