Determine \Theta for the following code fragment in the average case. Assume that all variables are of type "int".

              sum = 0;
              for (i = 0; i < n * n; i++)
                sum++;
            

\Theta(n^2)
  • \Theta(\log n)
  • \Theta(n \log n)
  • \Theta(1)
  • \Theta(n)
  • \Theta(n^2 \log n)
  • \Theta(n^3)
  • \Theta(2^n)

How much work is done by the body of the inner for loop?

How many times is the for loop executed? Multiply this by the amount of work done by the body.