146 views
1 votes
1 votes

What is the returned value by the  given function below.

Algo  fun(n)

{

    If(x<=2) return 1;

     Else {

          Return    fun(n1/2)   +   n; 

     }

}

Note : Assume that all the syntax and data type constraints are valid and just check algorithm. 

1 Answer

0 votes
0 votes
The time complexity of the following equation would be θ(n) with the help of change of variables and masters theorem method in algorithm.

If you are talking about the answer the answer than I think you are asking wrong question as for the answer of the equation we have to give input "n". for the code for this algorithm in c language here is the code.

#include <stdio.h>

int fun(int n) {
    if (n <= 2) {
        return 1;
    } else {
        return fun(n / 2) + n;
    }
}

int main() {
    int n = 10; // Example value of n
    int result = fun(n);
    printf("Result: %d\n", result);
    return 0;
}

Related questions

1 votes
1 votes
0 answers
1
srestha asked May 19, 2019
644 views
Let $A(n)$ denotes the number of $n$ bit binary strings which have no pair of consecutive $1’s.$ what will be recurrence relation for it and what will be it’s Time Co...
1 votes
1 votes
2 answers
2
srestha asked May 10, 2019
898 views
What is the solution of recurrence relation$T\left ( n \right )=T\left ( n-1 \right )+n$
1 votes
1 votes
1 answer
3
VikramRB asked Jan 20, 2019
1,062 views
What is the time complexity of the following recurrence relation and step to derive the same$T(n) = T(\sqrt{n}) + log(logn)$
1 votes
1 votes
1 answer
4
Mayankprakash asked Jan 4, 2019
1,336 views
T(n) = T(n/4) + T(3n/4) + nHow to solve these type of problems?Can I solve this using master theorm by considering X = T(3N/4) +N THEN T(N) = T(N/4) +XCAN WE SOLVE LIKE T...