← 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?
- A.O(n log n)
- B.O(n + k)
- C.O(n · k)
- 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 →