When you have a for loop, its total runtime is the sum of the runtimes of each individual iteration.
If all iterations have the same runtime, then the total runtime of the for loop is the number of iterations multiplied by the runtime of each iteration.
For instance if I write the code:
for (int i = 0; i < 10000; ++i)
{
std::cout << "Hello " << i << std::endl;
}
Then 10000 lines will be written to output, and you can say this is the runtime of your algorithm.
But if I write the code:
for (int i = 0; i < 10000; ++i)
{
some_complex_and_slow_function();
}
Then some_complex_and_slow_function()
will be called 10000 times, therefore the total runtime will be 10000 times the runtime of some_complex_and_slow_function()
.
In your case, you have a for loop with another for loop inside. So you need to find out: what is the runtime of the inner for loop (which is the same as asking how many iterations it has), and what is the number of iterations of the outer loop.
Please try to answer these two questions, and ask again if you still have doubts.