What is the function class of these 2 codes? I'm thinking O(N^2) for both of them.
int mystery3(int n){
int s = 0;
for (int i=1; i<=n; i++) {
int ci = 0;
for (int j=1; j<=i; j++){
ci+=1;
}
s += ci;
}
return s;
}
void say_hello(int n){
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
puts("hello");
}
}
}
Last edited on