AI Hints
Home›DSA in Python Tutorial›Counting Sort and Practice
DSA in Python · Lesson 60 of 132

Sorting Quiz

Test yourself.

⏱ 2 min read▶ Video at 1:10:05🎓 Free
Watch this lesson in the DSA in Python courseWatch on YouTube ↗Full DSA in Python course

You've now seen six sorting algorithms. Let's see what's stuck. Pause, answer, then listen.

Sorting Quiz
From the video: Sorting Quiz
  • Six sorting algorithms
  • What's stuck?
  • Pause and answer

Question 1

Which sort is O of N log N in every case, even the worst? The answer is merge sort. Quick sort can fall to O of N squared with bad pivots.

Quick check
O(n log n) even in the worst case?

Question 2

Which simple sort is fast on lists that are already nearly sorted? The answer is insertion sort, because each item only slides a little way.

Quick check
Fast on nearly sorted lists?

Question 3

Is Python's built in sort stable? Yes. Equal items keep their original order, so you can sort in several steps.

Quick check
Is Python's sorted() stable?

Question 4

When is counting sort a good choice? The answer is, when values are whole numbers in a small range, like marks out of a hundred.

Quick check
Counting sort is best for…

Summary

Excellent. Next, a new section. Trees, the structure behind file systems, databases, and much more.

Key takeaways
  • Merge: always O(n log n)
  • Insertion: nearly sorted
  • sorted() is stable
Next up: Trees — branching data