In: Computer Science
PYTHON
Write the time complexity of the code snippets in Big O notation. Also, add one/two lines to explain your answer.
1a
int a = 0, b
= 0; |
1b
bool isPrime(int N) {
if (N == 1) return false;
for (x = 2; x <= sqrt(N); x++) {
if (N % x == 0) {
return false;
}
}
return true;
}
1c
int a = 0, b = 0;
for (i = 0; i< N; i++) {
for (j = 0; j < N; j++) {
a += i + j;
}
}
for (k = 0; k < N; k++) {
b += k;
}
1d
FindMax(x, y) {
if (x > y) {
return x
}
else {
return y
}
}
1e
int a = 0, i = N;
while (i>0) {
a += i;
i /= 2;
}