Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   big oh notation (http://www.go4expert.com/forums/big-oh-notation-t23518/)

compscichick 8Oct2010 09:22

big oh notation
 
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)



All times are GMT +5.5. The time now is 00:41.