Examveda

What is the time complexity of the following recursive implementation to find the sum of digits of a number n?
#include<stdio.h>
int recursive_sum_of_digits(int n)
{
      if(n == 0)
        return 0;
      return _________;
}
int main()
{
      int n = 1201;
      int ans = recursive_sum_of_digits(n);
      printf("%d",ans);
      return 0;
}

A. O(n)

B. O(1)

C. O(len(n)), where len(n) is the number of digits in n

D. O(1/2)

Answer: Option C


This Question Belongs to Data Structure >> Miscellaneous On Data Structures

Join The Discussion

Related Questions on Miscellaneous on Data Structures