i := n;
WHILE i > 1
FOR j := i to n DO
X;
END
FOR j := 3*i to 3*n DO
X;
END
DEC(i); (* i decrement *)
END
For this pseudocode, I have to calculate a function f: N -> N, depending on n. I'm doing something like this for the first time, so I don't even know if my approach is correct. So, in the first line I have 1 constant time. The while loop runs n-1 times + n times comparison and n-1 constant time for decrement. The first for loop runs n-i+1 times. The second for loop runs 3n-3i+1 times. So (I think) that would be the formula: f(n)=1+((n-1)+n+(n-1))*((n-i+1)+(3n-3i+1)) and that would be f(n)=12n^2 -12ni -2n +8i -3
But now I have n
and i
variables? How do I get rid of the i
?