2

Apologies for this simple question. I found it in the book Algorithms by Sedgewick and Wayne.

Give a formula to predict the running time of a program for a problem of size N when doubling experiments have shown that the doubling factor is $2^b$ and the running time for problems of size N0 is T.

$$ \frac{T(2N)}{T(N)}=2^b.$$

$$ T(N_0)=T. $$

I am not sure how to proceed after that.

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
johnson
  • 123
  • 2

1 Answers1

0

Instead of solving the question for you, let me show you what steps you need to take in order to solve this problem on your own.

Suppose that $T(1) = T_0$ and $T(2n) = C T(n)$ for all $n$.

  • What is $T(2)$? What is $T(4)$? What is $T(8)$? What is $T(2^k)$?

Now suppose that $T$ is monotone: $T(n_1) \leq T(n_2)$ whenever $n_1 \leq n_2$.

  • If $2^k \leq n \leq 2^{k+1}$, what can you say about $T(n)$?
  • Can you now deduce the asymptotic rate of growth of $T(n)$ for arbitrary $n$?
Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
  • I can guess that it is $(N/N_0)^b$ but not too sure how to write a sequence of equations to show it. – johnson Dec 25 '17 at 15:09
  • Try working on it for a few hours. That's the only way to learn. – Yuval Filmus Dec 25 '17 at 15:11
  • You asked "what can you say about T(n)?". I'm not sure what else to say besides it is $\ge T(2^k) and \le T(2^{k+1})$ – johnson Dec 25 '17 at 15:26
  • I'm not sure how to find the answer for n which is not a power of 2 – johnson Dec 25 '17 at 15:28
  • It's in fact impossible, given just your recurrence formula. But you can find the asymptotic rate of growth ("big Theta", which is a stronger form of "big O"; see https://cs.stackexchange.com/questions/57/how-does-one-know-which-notation-of-time-complexity-analysis-to-use) assuming that $T$ is monotone. – Yuval Filmus Dec 25 '17 at 15:31
  • but don't we have the answer in $(N/N_0)^bT?$ – johnson Dec 25 '17 at 15:34
  • No, you only have the exact answer for $N=2^kN_0$. For other values of $N$, you can only get estimates assuming that $T$ is monotone. The formula you get for $N=2^kN_0$ is nice enough that you can actually interpret it for all values of $N$, but that's just a heuristic. – Yuval Filmus Dec 25 '17 at 15:34
  • So proceeding, $N_02^k\le N\le N_02^{k+1}$ therefore $T(N_02^k)\le T(N)\le T(N_02^{k+1}) $. There is still the extra information of $2^b$ how do we use that. – johnson Dec 25 '17 at 15:45
  • Yes, that's the idea. If you follow this route you'll indeed get $(N/N_0)^b T_0$ as a heuristic guess (and the intended answer), and $\Theta((N/N_0)^b T_0)$ as something you can prove assuming that $T$ is monotone. – Yuval Filmus Dec 25 '17 at 15:47
  • So $2^{kb}T\le T(N) \le 2^{(k+1)b}T$ – johnson Dec 25 '17 at 15:53
  • At this point I don't think you need my help any further. – Yuval Filmus Dec 25 '17 at 15:53
  • I think I somewhat understood it. But given a value of b is it possible to interpolate, or are we not given that information so it would not be right to guess. I.e. assume b is 2 and the function is quadratic, then would we get exact values for all N? – johnson Dec 25 '17 at 16:08
  • You're reading too much into this exercise. They expected answer is $(N/N_0)^b T_0$. – Yuval Filmus Dec 25 '17 at 16:10
  • Alright, thank you very much. Cheers :-) – johnson Dec 25 '17 at 16:11