Consider two algorithms A and B that take time in (n^2) and (n^3), respectively,
ID: 3664488 • Letter: C
Question
Consider two algorithms A and B that take time in (n^2) and (n^3), respectively, to solve the same problem. If other resources such as storage and programming time are of no concern, is it necessarily the case that algorithm A is always preferable to algorithm B? Justify your answer. Consider two algorithms A and B that take time in (n^2) and (n^3), respectively, to solve the same problem. If other resources such as storage and programming time are of no concern, is it necessarily the case that algorithm A is always preferable to algorithm B? Justify your answer. Consider two algorithms A and B that take time in (n^2) and (n^3), respectively, to solve the same problem. If other resources such as storage and programming time are of no concern, is it necessarily the case that algorithm A is always preferable to algorithm B? Justify your answer.Explanation / Answer
No, its not always necessary for the algorithm A to be better than algorithm B.
For example,
Suppose:
Algorithm A's time is 8 n^2.
Algorithm B's time is n^3.
So, for n < 8,
Algorithm B takes less time than Algorithm A.
So, for smaller inputs, it may be possible that for smaller values of n, B is faster than A