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