SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Floating point operations

    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

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is this correct?

    Generating a vector: O(constant)
    Sum the vector elements: O(n) or exactly (n-1)

  3. #3
    SitePoint Wizard Mike Borozdin's Avatar
    Join Date
    Oct 2002
    Location
    Edinburgh, UK
    Posts
    1,743
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by HakonHoy View Post
    Is this correct?

    Generating a vector: O(constant)
    Sum the vector elements: O(n) or exactly (n-1)
    If you filling a vector with values in a loop by "generating", then it is also O(n)

    As for summing, why is it O(n-1)? It is also O(n).


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •