Analyzing Alg. Runtime



//This is a homework assignment so I am not looking for the answer,
but possibly an explination of how to figure it out.


I am given the algorithm (on line 2 it is suppose to be "i (less than
or equal to) n")
GSSSum
1. sum = 0;
2. for (i = 0; i < n; ++i) {
3. prod = 1;
4. for (j = 0; j < i; ++j)
5. prod = prod * x;
6. sum = sum + prod; }
7. return sum;

(x is a given value and n is non-negative integer)
I am suppse to analyze the run time for each line and then Compute the
total run time.
This is what i came up with. Not sure how right it is:
1. 1
2. n+1
3. n
4.
5.
6.
7. 1

Could someone let me know if I'm on the right track for the ones I
filled in an give some hints for the others.

Thanks.

.



Relevant Pages

  • Re: Pi Estimate!!
    ... How accurate is the sum of 100 terms of this series? ... If this is all the resourcefulness you ... here for an exciting future career: ...
    (comp.soft-sys.matlab)
  • Re: Analyzing Alg. Runtime
    ... Brad skrev: ... but possibly an explination of how to figure it out. ... prod = 1; ... return sum; ...
    (comp.programming)