• edited by
1,403 views
1 1 vote

Consider the following function

int foo(int n) {
    int count1=0, count2=0;
    if (n < 0) n = -n;
    if (n == 0) return 1;
    If (n == 1) return 0;
    while (n) {
        if (n & 1) count1++;
        n = n >> 1;
        if (n & 1) count2++;
        n = n>>1;
    }
    return foo(abs(count1 - count2));
}


What is the time complexity for the above function?

Please log in or register to answer this question.

Position:
Show:

Related questions

0 0 votes
0 0 answers
1.8k
1.8k views
Naveen Kumar 3 asked Nov 3, 2018
1,791 views
Suppose, we have an array of n elements. find the time complexity to search two elements x, y such that:-a) x+y < 100b) x+y 1000Also, state the algorithm/approach for th...
1 1 vote
1 1 answer
1.8k
1.8k views
Akriti sood asked Jan 23, 2017
1,775 views
What is the time complexity of the following function foo() void foo() { int i, j; for(i = 1; i <= n ; i++) for(j = i; j <= log(i); j++) printf(“gate”); } what is the tim...
2 2 votes
1 answers 1 answer
2.0k
2.0k views
Akriti sood asked Jan 23, 2017
1,960 views
please tell the time complexity?i was getting O(2n)
1 1 vote
2 answers 2 answers
1.9k
1.9k views
sh!va asked Dec 4, 2016
1,862 views
for (int i = 1; i <=m; i += c){ -do something -}for (int i = 1; i <=n; i += c){ -do something - }What will the the tiem complexity of given code pseudococde?A. O (m...