The Algorithms course I am taking on Coursera does not require discrete math to find discrete sums. Dr. Sedgewick recommends replacing sums with integrals in order to get basic estimates.
For example: $$\sum _{ i=1 }^{ N }{ i } \sim \int _{ x=1 }^{ N }{ x } dx \sim \frac { 1 }{ 2 } N^2$$
How would I go about doing this for the problem below?
What is the order of growth of the worst case running time of the following code fragment as a function of N?
int sum = 0;
for (int i = 1; i <= N; i++)
for (int j = 1; j <= i*i*i; j++)
sum++;
What I've got so far:
$$\sum _{ i=1 }^{ N }{ } \sum _{ j=1 }^{ i^{ 3 } }{ } 1\approx \int _{ i=1 }^{ N }{ } dx\int _{ j=1 }^{ i^{ 3 } }{ } 1djdi$$
I'm not sure if this is correct, and I'm confused as to how to set these types of problems up. I've taken integral calculus, but it was almost 6 months ago. A hint in the right direction would go a long way.
The basic principle is the replace the summation variable with an integration variable.
$$\sum _{ i=1 }^{ N } i^k\approx \int _{ 0 }^{ N }{x^{k}}\operatorname dx = \frac{N^{k+1}}{k+1}$$
In this case you have a nested sum, so do a one-two step. $$\begin{align} \sum _{ i=1 }^{ N }\left( \sum_{j=1}^{i^3} 1\right) \approx & ~ \int_0^N \left( \sum_{j=0}^{x^3} 1\right)\operatorname d x \\ \approx & ~ \int _{ 0 }^{ N }\int_0^{x^3} 1\operatorname d y\operatorname dx \\ \approx & ~ \int _{ 0 }^{ N }x^3\operatorname dx \\ \approx & ~ \frac{N^4}4 \end{align}$$