Thread: big-Oh

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    43

    Question big-Oh

    I just need some help finding the run time of my program in the general big-Oh notation. what my program does is takes a 2d array of numbers adds all the possibilities to make 1d sets and then finds the highest sum of the of all the possible sets.
    ex
    given:
    Code:
    0    -2    -7    0
    
    9     2    -6    2
    
    -4    1    -4    1
    
    -1    8     0    -2
    the program makes
    Code:
    0   -2   -7     0     //first row
    9    0   -13    2     //first and second
    5    1   -17    3     //row 1-3
    4    9   -17    1     //row 1-4
    9    2   -6     2     //row 2
    5    3   -10    3     //row 2-3
    4    11  -10    1     //row 2-4
    -4   1   -4     1     //row 3
    -5   9   -4    -1     //row 3-4
    -1   8    0    -2     //row 4
    and the highers set sum of each line is
    Code:
    0
    9
    6      //5+1
    13     //4+9
    11     //9+2
    8      //5+3
    15     //4+11
    1
    9
    8
    then it displays the highest sum.

    what i got is O(n^3) (assuming m is about equal to n)
    and this is how...

    n = hight
    m = length

    for the first part...
    Code:
                S =   n  + n-1 + ... +  2  +  1
    +           S =   1  +  2  + ... + n-1 +  n
    --------------------------------------------
               2S =  n+1 + n+1 + ... + n+1 + n+1
               2S =  n(n+1)
                S = (n^2+n)/2
    that is for the number of new sets made

    and then add m, S times so... (m is about equal to n so i replace m with n)
    Code:
    m*S 
    = m * (n^2+n)/2
    = n(n^2+n)/2
    = (n^3+n^2)/2
    this give O(n^3)

    I'm not sure that I am using the length part right.

    I need to know because my program is also graded on efficiency, this is the first class that has done this, and i want to make sure i get the most points possible. I'm worried that I'm wrong because I came up with this solution in about an hour and according to my assignment O(n^3) is the best possible solution. So I want to make sure I didn't over look anything.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    There are Θ(n^2) new sets, that is true. What matters for efficiency is what you actually do to process those sets. If you isolate just one of your new sets, how much work does it take your code to find the highest partial sum in that set? That's the multiplier you need to multiply n^2 by.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    43
    i know it will take "m" to find the highest sum in each of the new sets. so i guess i was right, O(n^3), b/c n^2*m = n^3 (m is about the same as n). thanks for confirming.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How Big is Too Big
    By kpreston in forum C Programming
    Replies: 4
    Last Post: 10-25-2008, 10:16 AM
  2. Big and little endian
    By Cactus_Hugger in forum C Programming
    Replies: 4
    Last Post: 10-12-2005, 07:07 PM
  3. Big Buttons in IE 6
    By moonwalker in forum Tech Board
    Replies: 2
    Last Post: 07-13-2003, 07:04 PM
  4. Big endian/Little endian conversion
    By bonkey in forum Windows Programming
    Replies: 5
    Last Post: 09-25-2002, 02:29 PM
  5. Looking for some big C/C++ projects
    By C-Dumbie in forum C Programming
    Replies: 5
    Last Post: 09-16-2002, 12:18 AM