Practice question · Put in order
Order the recommended design workflow, which puts correctness before speed.
- Write an algorithm and argue why it is correct
- Measure how its cost grows with input size
- Only then rewrite it to run faster
- Work out precisely what the correct output is for every input
Hints
- The pitfall warns against doing the last step too early.
- You cannot sensibly optimize something you have not yet shown to be correct.
Show the answer
- Work out precisely what the correct output is for every input
- Write an algorithm and argue why it is correct
- Measure how its cost grows with input size
- Only then rewrite it to run faster
Why
Establish what is correct, build and justify a correct method, analyze its cost, and optimize last. Optimizing before correctness is the named pitfall.
Practise What Makes an Algorithm Good
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 What Makes an Algorithm Good
- The lesson says an algorithm must be finite and definite. Select every description that violates at least one…
- An O(n log n) sort loses to an O(n²) insertion sort on a 20-element array, and every production sort library…
- Match each quality or property to its meaning.
- A set of instructions counts as a genuine algorithm only if it is finite (it always stops) and definite…