🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Counting Sort and Custom Sorting: all 13 questions

Quiz: Counting Sort and Custom Sorting · Question 2 of 13

What is the time complexity of counting sort for n numbers in the range 0..k?

What is the time complexity of counting sort for n numbers in the range 0..k?

  1. A.O(n log n)
  2. B.O(n + k)
  3. C.O(n · k)
  4. D.O(k log k)
Answer & explanation

Correct answer: O(n + k)

One pass counts the n numbers and one pass walks the k + 1 counters.

Can you get the rest right without peeking?

Take the timed Quiz: Counting Sort and Custom Sorting quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →