Big O notation / algebraic formula

Page 1 of 1

3 Replies - 233 Views - Last Post: 01 February 2013 - 05:23 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=310825&amp;s=27ce804707c6ecc824412245cac73b29&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 rick2993

Reputation: 0
• Posts: 3
• Joined: 01-February 13

Big O notation / algebraic formula

Posted 01 February 2013 - 05:05 PM

Hey everyone. I can't seem to figure out the big O notation or the algebraic formula as it applies to this snippet of code.

I'm assuming it is O(n^2)?

Can anyone confirm this or help me out with the algebraic forumla?
e.g. N^2 + 3n

```for ( outerLoop = n - 1; outerLoop >= 0; outLoop++)
{
for (innerLoop = 0; innerLoop < outerLoop; innerLoop++)
{
{
}
}
}

```

ahhh sorry about the looks of the code. idk how to edit so here it is w/ indents

```for ( outerLoop = n - 1; outerLoop >= 0; outLoop++)
{
for (innerLoop = 0; innerLoop < outerLoop; innerLoop++)
{
{
}
}
}

```

Is This A Good Question/Topic? 0

Replies To: Big O notation / algebraic formula

#2 macosxnerd101

• Self-Trained Economist

Reputation: 10117
• Posts: 37,283
• Joined: 27-December 08

Re: Big O notation / algebraic formula

Posted 01 February 2013 - 05:18 PM

There are n steps, so the series is equivalent to n(n+1)/2. There are three steps in the inner loop, so multiply by 3. So T(n) = 3/2 (n^2 + n), which is O(n^2).

#3 rick2993

Reputation: 0
• Posts: 3
• Joined: 01-February 13

Re: Big O notation / algebraic formula

Posted 01 February 2013 - 05:22 PM

Thanks you!

#4 macosxnerd101

• Self-Trained Economist

Reputation: 10117
• Posts: 37,283
• Joined: 27-December 08

Re: Big O notation / algebraic formula

Posted 01 February 2013 - 05:23 PM