I need your help analyzing this algorithm

I have the following algorithm for evaluating a polynomial and I must find the total number of multiplications and the number of additions made by this algorithm

//This algorithm computes the value of polynomial P at a given point x

//Input: P[0..n] of the coefficients of a polynomial of degree n, stored from the lowest to highest and a number x

//Output: the value of the polynomial at the point x

BruteForcePolynomialEvaluation(P[0..n], x)

p = 0.0

for i = n down to 0

power = 1

for j = 1 to ido

power = power * x

p = p + p[i] * power

return p

Here is my analysis of this algorithm to figure out # of multiplications and additions:

Since there are two multiplication operations in the nest for loops I come up with the following summation for # of multiplications:

[Summation(i = 1 to n)] [Summation(j = i to n)] 2

For # of additions I have the following:

[Summation(i = 1 to n)] [Summation(j = i to n)] 1

In other words the number of multiplication is 2 times the number of addition. Could anyone help me verify whether my analysis for the number of multiplications and additions is correct?

[1431 byte] By [darklord12a] at [2007-10-1 12:33:34]
# 1
Correction for the summations in my last post:Number of multiplications:[Summation(i = 1 to n)] [Summation(j = 1 to n)] 2Number of additions:[Summation(i = 1 to n)] [Summation(j = 1 to n)] 1
darklord12a at 2007-7-10 14:52:14 > top of Java-index,Other Topics,Algorithms...
# 2
>> Could anyone help me> verify whether my analysis for the number of> multiplications and additions is correct?Why not implement the algorithm and add statemnts to increment counters every time a multiply and add take place?
sabre150a at 2007-7-10 14:52:14 > top of Java-index,Other Topics,Algorithms...
# 3
I am trying to learn the habit of just by looking at the algorithm and analyze it instead of code it. Coding help in this case but with a longer algorithm, it takes a long time.
darklord12a at 2007-7-10 14:52:14 > top of Java-index,Other Topics,Algorithms...
# 4

> I am trying to learn the habit of just by looking at

> the algorithm and analyze it instead of code it.

> Coding help in this case but with a longer

> r algorithm, it takes a long time.

Good habit, don't loose it.

The outer loop goes n, n-1, n-2 down to 1. The inner loop goes

1 .. n

1 .. n-1

..

1 to 1

with each inner loop iteration there are 2 'multiplies' and one 'add'.

The summation of (1..n), (1.. n-1) down to 1 is

n + (n-1) + (n-2) .. 1 = n(n+1)/2

Therefore, 'adds' = n(n+1)/2 and 'multiplies' = n(n+1).

sabre150a at 2007-7-10 14:52:14 > top of Java-index,Other Topics,Algorithms...
# 5
Thank you. Your analysis helps. Before I was able to see it the same way, but can only express it in English, not quite in number.
darklord12a at 2007-7-10 14:52:14 > top of Java-index,Other Topics,Algorithms...