I need to calculate the time complexity of the following loop:
for (i = 1; i < n; i++)
{
statements;
}
Assuming n = 10,
Is i < n;
control statement going to run for n time and i++;
statement for n-1 times? And knowing that i = 1;
statement is going to run for a unit of time.
Calculating the total time complexity of the three statements in for-loop yields 1+n+n-1 = 2n and the loop with its statements yields 2n+n-1 = 3n-1 = O(n).
Are my calculations correct to this point?