An algorithm takes 0.5 seconds to run on an input of size 100. How long will it take to run on an input of size 1000 if the algorithm has a running time that is linear? quadratic? log-linear? cubic?

Respuesta :

Answer:

linear: 5s

quadratic: 50s

log-linear: 0.75 s

cubic: 500s

Step-by-step explanation:

Let [tex]t_1,t_2[/tex] be the running time associated with the input of sizes [tex] s_1,s_2[/tex]

If the running time is linear

[tex]t_2 = t_1\frac{s_2}{s_1} = 0.5*\frac{1000}{100} = 0.5*10 = 5s[/tex]

If the running time is quadratic

[tex]t_2 = t_1\left(\frac{s_2}{s_1}\right)^2 = 0.5*\left(\frac{1000}{100}\right)^2 = 0.5*10^2 = 50s[/tex]

If the running time is log-linear

[tex]t_2 = t_1\frac{log(s_2)}{log(s_1)} = 0.5*\frac{log(1000)}{log(100)} = 0.5*1.5 = 0.75s[/tex]

If the running time is cubic:

[tex]t_2 = t_1\left(\frac{s_2}{s_1}\right)^3 = 0.5*\left(\frac{1000}{100}\right)^3 = 0.5*10^3 = 500s[/tex]

Q&A Education