1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Big O Help

Discussion in 'Software Development' started by tenniskev18, Sep 26, 2008.

Thread Status:
Not open for further replies.
  1. tenniskev18

    tenniskev18 Thread Starter

    Joined:
    May 11, 2007
    Messages:
    18
    Hey guys/girls.

    I am having issues determining the Big O for this set of loops.

    for(int i =0; i < n; i++)
    for(int j = 0; j < i*i; j++)
    for(int k = 0; k < j; k++)
    sum++;

    I know that the two outmost loop is O(n) and the middle loop is O(n^2), but I cant quiet determine what the third loops big O is... When I run the code I am getting 162 as the number of iterations.

    Also:

    for(int i = 1; i < n; i++)
    for(int j = 1; j < i*i; j++)
    if(j%i == 0)
    for(int k = 0; k<j; k++)
    sum++;

    The outmost loop is n, the middle is n^2, but I cant figure out what the last loops big O is.

    Anyone have any suggestions or comments?

    Thanks
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/753670

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice