Race Your Sort
In Notes 04 you watched sorting algorithms race on a few dozen cards. This week you enter the race yourself: write one sort with your own hands, then put it on the starting line against Python's built-in sorted() — a professional racer tuned by experts for decades. On 20,000 numbers, you will lose. Losing is expected. Understanding why you lost is the entire project.
That's it. There is no report, no analysis document, no slides — one small program, one race, one screenshot, one honest sentence. If this takes you more than an hour, you are overthinking it.
One more thing, because every racer needs a name: in your README you may give your sort a racing name. Lightning McQueue. The Brooklyn Bubble. Sir Swaps-a-Lot. This is worth zero points and is strongly encouraged.
The whole projectThree steps
Build your racer
Pick one sort from Notes 04 — insertion sort or merge sort (quicksort is fine too if you're feeling bold) — and write it from scratch in Python, in a file called mysort.py, as a function my_sort(nums) that returns the list in order. The only rule: no sorted() and no .sort() anywhere inside it. Those are the competition — you can't put the other racer's engine in your car. Test it on a short list first: my_sort([3, 1, 2]) should give [1, 2, 3].
Run the race
Copy the timing script below into race.py next to your file and run it. It races your sort against sorted() on the three input shapes from class — shuffled, already sorted, and reversed — 20,000 numbers each, and prints three lines. (If you named your function something else, fix the import line.) Heads-up: insertion sort on 20,000 reversed numbers can take a minute. Let it run — that slow minute is the result.
Write one sentence
Look at the three printed times. In your README, write one sentence: which input shape made your sort look best (or worst), and why you think that happened. One sentence. Not a paragraph. Not a report. Example: "Already-sorted was my best shape because insertion sort just walks down the list confirming each card is already home."
Provided codeThe timing script
This is the whole harness — you don't write any timing code yourself. It clocks each racer with time.perf_counter() and hands every racer a fresh copy of the same numbers, so nobody gets a head start.
import random, time from mysort import my_sort # your sort, in mysort.py def clock(sort_fn, data): start = time.perf_counter() sort_fn(list(data)) # fresh copy every run return time.perf_counter() - start nums = [random.randint(0, 999_999) for _ in range(20_000)] shapes = [("shuffled", nums), ("already sorted", sorted(nums)), ("reversed", sorted(nums, reverse=True))] for name, data in shapes: print(f"{name:>14}: mine {clock(my_sort, data):8.3f} s sorted() {clock(sorted, data):8.3f} s")
The output is three lines, something like shuffled: mine 9.412 s sorted() 0.002 s. Those three lines, in a screenshot, are your experimental evidence. That gap of a few thousand times is not embarrassing — it's the n² and n log n curves from Notes 02, plus thirty years of professional engineering, showing up live on your own machine.
SubmissionWhat you hand in
- Your code — a link to a GitHub repo containing
mysort.py,race.py, and a README with your one sentence (and your racer's name). A single attached.pyfile with the sentence in a comment at the top is also perfectly fine. - One screenshot of your terminal showing the three printed timing lines.
No report. No analysis document. No slides. No plots. If you submit a PDF, I will be confused. Late submissions lose 10% per calendar day, per the course policy.
GradingFive checkboxes, 20 points each
Each box is pass/fail. There is no partial credit inside a box and no rubric beyond this table.
| Checkbox | Points | |
|---|---|---|
| ☐ | The sort is yours and it's correct. No sorted() or .sort() inside it — and I will run my_sort on a list of my own and it comes back in order. | 20 |
| ☐ | The race runs. race.py executes without errors and prints three timing lines. | 20 |
| ☐ | All three shapes raced. Shuffled, already sorted, and reversed — about 20,000 numbers each. | 20 |
| ☐ | The screenshot matches the code. The numbers in the picture are plausibly what the submitted code produces. | 20 |
| ☐ | The README sentence shows you looked at the numbers. It names your best or worst shape and takes a real guess at why. | 20 |
| Total | 100 |
FAQThree questions, three answers
Mine is way slower than sorted(). Did I fail?
No — that's the point of the race. sorted() is written in C and tuned by professionals; your sort is honest Python written this week. Nothing in the checkbox table rewards speed. What's graded is that the race ran and that your one sentence shows you looked at the numbers and thought about them.
Can I do quicksort instead of insertion or merge?
Sure — any sort from Notes 04. Same rules: written from scratch, no sorted() or .sort() inside.
Do I need plots or charts?
No. The three printed times are the whole experiment. A screenshot of them is the whole evidence.