...

/

Solution: Big O of a Nested Loop with Addition

Solution: Big O of a Nested Loop with Addition

Review the solution to calculate the time complexity of the nested loop with addition.

We'll cover the following...

Solution #

Press + to interact
int n = 10; // 'n' can be anything, this is just an example
int sum = 0;
double pie = 3.14;
for (int var = 1; var < n; var += 3)
{
System.Console.WriteLine(pie);
for (int j = 1; j < n; j += 2)
{
sum += 1;
System.Console.WriteLine(sum);
}
}

Explanation

The for (int var = 1; var < n; var += 3) line gets executed n3\frac{n}{3} ...