Question

calculate the complexity of the below recursive code

Int f(int n)

{

If(n

return 1;

return f(n/2)+f(n/2);

}

A T(n)= 2T(n/2)+O(1) Correct Answer Incorrect Answer
B T(n)= T(n/2)+O(1) Correct Answer Incorrect Answer
C T(n)= 2T(n/4)+O(1) Correct Answer Incorrect Answer
D T(n)= 2T(n/6)+O(1) Correct Answer Incorrect Answer
E none Correct Answer Incorrect Answer

Solution

Here the function is recursively calling on f(n/2) twice and also one line for the condition when n=0. Hence 1 is the correct choice.

Practice Next
×
×