1.

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 inputI had been asked this question in an international level competition.My question is from Sorting topic in section Sorting of Data Structures & Algorithms II

Answer»

The correct choice is (d) O(n+k) k=range of input

Easiest 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).



Discussion

No Comment Found

Related InterviewSolutions