1. Factorial program using
2.
Will it be O(12) or something else?
3.
and
Does the big-O automatically become O(logN)?
5.
Will it be O(n^n) or O(n) only.
a. Iteration
b. Recursion
b. Recursion
2.
Code:
for(int i = 0; i < 3; i++) { //linear
for(int j = 0; j < 4; j ++){ // log (n)
//do constant time stuff
}
}
3.
Code:
for(int j = 0; j < n; j *= 2){
//do constant time stuff
}
Code:
for(int j = 0; j < n; j *= 10){
//do constant time stuff
}
5.
Code:
for(int i = 0; i < n*n; i++) {
cout << i << endl;
}
Comment