Floating point operations

Discussion in 'Programming' started by mitchbuch, Feb 24, 2010.

  1. #1
    How many floating point operations are needed to generate a vector using a for-loop:

    for ("0 to n")
    v = element(i+1)

    each element in the vector is : 1/(i^2)

    Also, how many floating point ops are needed to sum all the elements in a vector using a for loop?

    looks something like:

    for(0 to n)
    sum = sum+i
     
    mitchbuch, Feb 24, 2010 IP
  2. mitchbuch

    mitchbuch Active Member

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #2
    Is this correct?

    Generating a vector: O(constant)
    Sum the vector elements: O(n) or exactly (n-1)
     
    mitchbuch, Feb 24, 2010 IP
  3. NeoCambell

    NeoCambell Peon

    Messages:
    456
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    (number of floating point operations required for 1 iteration) X (number of iterations)

    In terms of algorithm efficiency,

    Generating a vector: O(Constant)
    Sum the vector elements: O(n)

    is correct according to my knowledge.

    But if the question asks algo efficiency to "Generate vectors", it is O(n).
     
    NeoCambell, Feb 25, 2010 IP