1

Consider the following pseudo code:

a <- [0,0,0] (initializing a 3d vector to zeros)

b <- [0,0,0] (initializing a 3d vector to zeros)

c <- a . b (Dot product of two vectors)

In the above pseudo code, what is the flop count (i.e. number floating point operations)?
More generally, what I want to know is whether initialization of variables counts towards the total floating point operations or not, when looking at an algorithm's complexity.

user6952886
  • 423
  • 1
  • 4
  • 7
  • Well, no, but then if you decide to to use floating-point operations as a measure of complexity then it is of course up to you to determine that they are the limiting factor of the implementation. – doynax Mar 05 '17 at 14:08

1 Answers1

2

In your case, both a and b vectors are zeros and I don't think that it is a good idea to use zeros to describe or explain the flops operation. I would say that given vector a with entries a1,a2 and a3, and also given vector b with entries b1, b2, b3. The dot product of the two vectors is equal to aTb that gives

aTb = a1*b1+a2*b2+a3*b3

Here we have 3 multiplication operations (i.e: a1*b1, a2*b2, a3*b3) and 2 addition operations. In total we have 5 operations or 5 flops. If we want to generalize this example for n dimensional vectors a_n and b_n, we would have n times multiplication operations and n-1 times addition operations. In total we would end up with n+n-1 = 2n-1 operations or flops. I hope the example I used above gives you the intuition.

Dilan
  • 2,610
  • 7
  • 23
  • 33
furkat
  • 41
  • 5