1.

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)This question was posed to me in an online interview.Origin of the question is Sorting in section Sorting of Data Structures & Algorithms II

Answer»

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

To explain: 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.



Discussion

No Comment Found

Related InterviewSolutions