If a problem of complexity 2n^2 + n can be solved in 24 units of time for n = 2, how long does it take for n = 4?
I was told that the answer is 48. But I believe it should be 24^2 because the complexity of the algorithm is O(n^2).
Appreciate if anyone could enlighten me.
The complexity O(f(n)) comprises all computations that take c*f(n)+d amount of time, where c and d are constants. If d=0 then:
In the case for n=2 and complexity O(2n^2+2) being 24:
24 = (2*2^2 + 2)*c, hence c = 24/10 = 2.4
Now we compute for n=4:
(2*4^2+4)*2.4= 36*2.4 = 86.4 units of time
If d is not 0 the c = (24-d)/10 and for n=4 it would take
36*(24-d)/10 +d = 86.4 +0.9d
So, it is impossible for the answer to be 48, which additionally implies a linear algorithm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With