Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Big O notation / algebraic formula

$
0
0
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++)
{
if (menuList [ innerLoop ].getMenuName().compareToIgnoreCase(menuList[innerLoop + 1].getMenuName()) > 0)
{
total = menuList[inner Loop];
menuList[innerLoop] = menuList[innerLoop + 1];
menuList[innerLoop + 1] = total;
}
}
}



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++)
     {
          if (menuList [ innerLoop ].getMenuName().compareToIgnoreCase(menuList[innerLoop + 1].getMenuName()) > 0)
          {
               total = menuList[inner Loop];
               menuList[innerLoop] = menuList[innerLoop + 1];
               menuList[innerLoop + 1] = total;
          }
     }
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>