Exam-style question
Try this first
A developer is choosing between two algorithms for an automated system. Algorithm X usually completes quickly but requires a large amount of memory as the problem grows. Algorithm Y takes longer but uses much less memory. Discuss how the developer should compare these algorithms and decide which is appropriate.
Model answer
What a good answer should say
- The developer should compare the algorithms as functions of the problem size rather than relying on a single test.
- Algorithm X may be preferable when rapid completion is the main requirement and sufficient memory is available.
- Algorithm Y may be preferable when memory is limited or when minimising resource use is more important than speed.
- The developer should consider the expected size of the problems, the required running speed, and the available memory.
Explanation
Why this works
There is not always one algorithm that is best in every respect. Comparing both time and space efficiency against the expected problem size supports an informed design decision and helps the system run quickly while using suitable resources.
Common mistake
No common mistake is linked to this question yet.
