Determine \Theta
for the
following code fragment in the average case. Assume that all
variables are of type "int".
for (i = 0; i < n - 1; i++) for (j = i + 1; j < n; j++) { tmp = AA[i][j]; AA[i][j] = AA[j][i]; AA[j][i] = tmp; }
\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 inner for loop executed? Multiply this by the amount of work done by the body.
How many times is the outer for loop executed? Multiply this by the amount of work done by the inner for loop.