edited by
676 views
1 votes
1 votes

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?

edited by

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
1
Naveen Kumar 3 asked Nov 3, 2018
967 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 votes
1 votes
1 answer
2
Akriti sood asked Jan 23, 2017
1,305 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...
2 votes
2 votes
1 answer
3
1 votes
1 votes
2 answers
4
sh!va asked Dec 4, 2016
960 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...