Analyzing Alg. Runtime
- From: "Brad" <yoda_132002@xxxxxxxxxxx>
- Date: 29 Jan 2007 09:54:26 -0800
//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.
.
- Follow-Ups:
- Re: Analyzing Alg. Runtime
- From: Pascal Bourguignon
- Re: Analyzing Alg. Runtime
- Prev by Date: Re: Algorithm to find break in contiguity
- Next by Date: Re: IIS and programing in .NET
- Previous by thread: hey help in solving the following recurrence...
- Next by thread: Re: Analyzing Alg. Runtime
- Index(es):
Relevant Pages
|