What is the time complexity of fun()?
int fun(int n) {
int count = 0;
for (int i = 0; i < n; i++)
for (int j = i; j > 0; j--)
count = count + 1;
return count;
}
int fun(int n)
{
int count = 0;
for (int i = 0; i < n; i++)
for (int j = i; j > 0; j--)
count = count + 1;
return count;
}
int fun(int n) {
int count = 0;
for (int i = 0; i < n; i++)
for (int j = i; j > 0; j--)
count = count + 1;
return count;
}
def fun(n):
count = 0
for i in range(n):
for j in range(i, 0, -1):
count += 1
return count
int Fun(int n) {
int count = 0;
for (int i = 0; i < n; i++)
for (int j = i; j > 0; j--)
count++;
return count;
}
function fun(n) {
let count = 0;
for (let i = 0; i < n; i++)
for (let j = i; j > 0; j--)
count++;
return count;
}
Theta (n)
Theta (n2)
Theta (n*log(n))
Theta (n*(log(n*log(n))))
This question is part of this quiz :
Top MCQs on Complexity Analysis of Algorithms with Answers