Programming Fundamentals · What You Can Do Now

Run a Complexity Checkup on AI-Written Code

The Algorithms Part finale: take a real piece of AI-written code through a full checkup—self-report → optimize → measure. Pick one of three tiers by how much time you’ll put in; 30 minutes to start. Reach tier three and you’ll see with your own eyes whether the complexity AI claimed was bluffing.

Pick a tier · start today
🥉

Task 1 · Account for itself

Have AI label the complexity of its own code

30 min

Take a function AI just wrote (if you don’t have one, ask it to write “find the common elements of two lists”—nine times out of ten it hands you an O(n²) version first). Drop the prompt below on it and make it confess how fast or slow it is.

For the function you just wrote, do a complexity self-check. Answer in plain language: 1. Line by line (or loop block by loop block), label the time complexity; for each spot, explain why in one sentence; 2. Clearly point out the bottleneck line: which line / loop is the slowest in the whole function? Why that one? 3. Summarize: what are the overall time complexity and space complexity? 4. Translate into human terms: if the data grows from 1,000 to 1,000,000, how many times slower does this function get? Will users feel “nothing,” “a brief hitch,” or “spin until you question your life choices”? I’m a beginner—don’t pile on jargon; use analogies when you can.
Done when: you can point at the code and say “the bottleneck is this line, because it’s a nested loop / a full scan”—once you can name the bottleneck line, this tier is done.
🥈

Task 2 · Optimize one tier

Demand a speedup—and demand it spell out the cost

Half a day

Follow Task 1: if AI self-reported O(n²), ask it to optimize to O(n log n) or O(n)—but the point isn’t just going faster; it’s making it spell out the cost. After finishing ds-6, you should be able to point to which line in its plan is “trading space for time.”

Please optimize the O(n²) function above to O(n log n) or O(n). Requirements: 1. Keep both old and new versions; add comments on the critical optimization lines; 2. Explain clearly what technique you used to speed it up (sort then binary search? switch to a hash table?), and which family of algorithm ideas it belongs to; 3. Honestly state the cost: did readability get worse? How much more memory? Are there scenarios where the old version is actually better (e.g. very small data)? 4. If your plan “trades space for time,” clearly point out which line, how much space buys how much time. Finally, give me a quiz: ask me to point out where “trade space for time” happens in the new version, then reveal the answer.
Done when: you correctly answer its quiz—being able to point with your own hand to which line “trades space for time” means ds-6 and this chapter actually connected.
🥇

Task 3 · Measure until it can’t bluff

Verify with real data that it isn’t bluffing

One week

Complexity is paper reasoning; the timing curve is hard evidence. Have AI write a benchmark script, generate three scales of random data, time each run, and see with your own eyes how far the before/after curves diverge—and check whether the complexity it self-reported was bluffing.

Please write a benchmark script for both the old and new versions of the function. Requirements: 1. Generate three tiers of random test data: 1,000 / 100,000 / 10,000,000 rows (if 10M won’t run, you’re allowed to drop to 1M and explain why); 2. For each tier, run old and new versions 3 times each, take the average time, and output a comparison table: data size | old time | new time | speedup; 3. The script must run as-is—tell me which command to use and roughly how long to wait; 4. After the runs, help me judge: does the measured growth trend match the complexity you self-reported earlier? If not (e.g. you claimed O(n) but it grows like a square), analyze honestly why. I’ll paste the measured results back; you interpret the curves.
Done when: you have a measured timing table across three data sizes, and you can answer “does the measured curve match the self-reported complexity?”—match or call the bluff, either way the checkup is complete.
🩺 Checkup report generator · fill three fields, get a summary you can share in the group chat
Fill all three fields so the report is complete~
Why insist on measuring?AI’s self-reported complexity is right most of the time—but “most” ≠ “every time.” Sorting hidden inside library calls, string concat quietly inside a loop—any of these can make the real curve disagree with the paper math. Anyone who’s run a benchmark once keeps a professional suspicion toward “it said O(n), so it is O(n).” That’s exactly the posture a reviewer should have.

✅ What this lesson wants to share