Practice question · Multiple choice
A team spends a week optimising a function that accounts for 2% of runtime. What did they get, and what is the rule they violated?
Hints
- If a part is 2% of the total and you make it infinitely fast, what happens to the total?
- Ask what they should have done in the first hour.
Show the answer
D. At most a 2% improvement, since the other 98% dominates
Why
Making 2% of the runtime instantaneous saves 2%, so the ceiling was set before they started. Profiling first is the discipline, and the reason it matters is that developers guess hot spots badly, which is why 'measure, don't guess' outranks any particular optimisation technique.
Practise Complexity and Performance Trade-offs
The app has 6 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.
More questions on Complexity and Performance Trade-offs
- Two algorithms are timed on one machine: the O(n) one takes 3 seconds at n = 1000 and the O(n²) one takes 1…
- An O(n log n) sort applied to a nearly-sorted list can be slower than an O(n²) insertion sort on the same…
- Order these growth classes from the slowest-growing to the fastest-growing as n becomes large.
- Big-O notation compares how algorithms scale, so an O(nlog n) algorithm always runs faster than an O(n²) one…