In: Computer Science
Suppose an algorithm A1 has a runtime T1(n) defined ( in seconds) by the following function
T1(n) = n3 + 20n + 15
For n = 13, the runtime of the algorithm is 2472 seconds. Let us assume that we have an algorithm A2 with runtime given by T2(n) = n2 + 22n + 14? What will be the lowest value of n for which the runtime of A2 exceeds 2472 seconds?
**Urgently needed**
To find a value of T2(n) = n2 + 22n + 14 in such a way that it exceeds 2472 seconds, following steps are to be done:
Step 1: Take n2 + 22n + 14 = 2472 and find the value of n. This is to be done as on substituting the value of n the result shouls be more than 2472. So fist find the value of n for which T2(n) = 2472.
so, n2 + 22n + 14 = 2472
=> n2 + 22n + 14 - 2472 = 0
=> n2 + 22n -2458 = 0
Now use discriminant method to solve the equation: any equation is of the form ax2 + by +c =0
D = sqroot(b2-4*a*c) = sqroot((22)2 - 4*1*(-2458)) = 101.56 = positive
Hence, value of n exists.
so, n = (-b
D) / 2*a
n = (-22
101.56) / 2 *1
on solving n = 39.78 and -61.78
negative value of n is not acceptable. So n = 39.78. To get the lowest n approximate it to 40.
Step 2 :
The value should come out to be more than 2472. so put the value as 40.
So, T2(n) = n2 + 22n + 14 = (40)2 + 22*40 + 14 = 2494.
Answer : Therefore lowest possible value of n =40.