🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Counting Sort and Custom Sorting: questions with answers

13 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. What does this print? (code)
  2. Q2. What is the time complexity of counting sort for n numbers in the range 0..k?
  3. Q3. When is counting sort a BAD idea?
  4. Q4. A stable sort orders [("A", 2), ("B", 1), ("C", 2)] by the number. What is the result?
  5. Q5. Which Python key sorts students by marks high to low, then by name A to Z?
  6. Q6. Why is (a, b) - a - b a risky Java comparator?
  7. Q7. Which line sorts an Integer[] nums in descending order in Java?
  8. Q8. What does this print? (code)
  9. Q9. What does this print? (code)
  10. Q10. You sort students by name, then sort the result by marks using a stable sort. What happens to students with equal marks?
  11. Q11. What does this print? (code)
  12. Q12. Which Java comparator safely sorts an Integer[] from smallest to largest, even with very large values?
  13. Q13. Why can counting sort beat the O(n log n) limit for sorting?