1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

big oh notation

Discussion in 'C' started by compscichick, Oct 8, 2010.

  1. compscichick

    compscichick New Member

    Joined:
    Sep 7, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    will someone just check my answers? I am having trouble getting the hang of big oh notation, so my teacher gave me some extra practice to turn in. I just wanted to see if I was on the correct track.

    Code:
    void Ex2(int n){
    int a;
    for (int i=0; i<n; i+=2)a=i;
    }
    f(n)=n+2
    O(n)
    
    void Ex3(int n){
    int a;
    for(int i=0; i<n*n;i++) a=i;
    }
    
    f(n)=n^2-1
    O(n^2)
    
    void Ex4(int n){
    int a;
    for(int i=0; i<n; i++)
    for(int j=0; j<=i;j++) a=i;
    }
    f(n)=???
    O(n^2)
    
    void Ex5(int n){
    int a;
    for(int i=0; i<n*n;i++)
    for( int j=0; i<=i; j++) a=i:
    }
    f(n)=n^2(n(n+1)/2)
    O(n^4)
     
    Last edited by a moderator: Oct 8, 2010

Share This Page