1,208 views

2 Answers

Best answer
10 votes
10 votes
int foo(int n)
{
    if(n > 10000)
        return 1;
    int sum = 0, i;
    for( i = 0; i < n; i++)
    {
        sum += i;
    }
    return sum;
}


for loop will run 10000 times. 
Sum is sum of 1st 9999 natural numbers.
Sum = 9999*10000/2 = 49995000 = Θ(1)
selected by
0 votes
0 votes

Answer : C

WE always take very large value of n to find Time Complexity . so , here we can ignore loop because it will run only for n <= 10000 . so, here for n > 10000 it run only for 1 time for any large value . so , time complexity = Big Theta(1) // which is average case time complexity

Answer:

Related questions

3 votes
3 votes
2 answers
2
1 votes
1 votes
3 answers
3
3 votes
3 votes
4 answers
4
Arjun asked Oct 18, 2016
774 views
What will be the output of the following code?#include <stdio.h int main() { char a = 'A', z = 'Z'; printf("%d", z-a); }