...
Question 9570 – Time-Complexity
February 13, 2024
Question 9573 – Time-Complexity
February 13, 2024
Question 9570 – Time-Complexity
February 13, 2024
Question 9573 – Time-Complexity
February 13, 2024

Question 9571 – Time-Complexity

The time complexity of the following C function is (assume n > 0)

int recursive (int n) {
   if (n == 1)
   return (1);
   else
   return (recursive (n - 1) + recursive (n - 1));
} 

Correct Answer: D

Question 22 Explanation: 
if (n==1)
return(1)
else
return(recursive(n-1) + recursive(n-1))
n>0:
T(2) = T(1) + T(1) = 2T(1)
T(3) = T(2) + T(2) = 2T(2) = 2⋅2T(1) = 22T(1)
T(4) = 23⋅T(1)

T(n) = 2n⋅T(1) = O(2n)
A
O(n)
B
O(n log n)
C
O(n2)
D
O(2n)
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!