I am trying to work my way through some computer science training and I am not able to properly understand the following pseudo code:
COUNTING-1 (n) cost times
1 for r=1 to n c1 n+1
2 for c=1 to n c2 n(n+1)
3 sum = sum+1 c3 n2
4 return sum c4 1
T(n)=c2*n(n+1)+c3*n2 +c1*(n+1)+c4=an2+bn+c
Could someone explain why the outer loop is n+1, and not just n?
Also what are the constants c, a and b? I don't understand why they need to factor into the explanation equation as it isnt clear what their value will.
Apologies if these are really simple questions. If there are some useful things I should read I would appreciate a pointer in the right direction.
*Edit: I think looking at it again the c constant is the cost of the operation which for each is constant time, so 1. Is the cost of a single operation ALWAYS 1? If it is (which it appears to be in this RAM model) what is the point in over complicating the formula underneath with those values?
Why not just T(n)=n(n+1) + n2 + (n+1)