Sail E0 Webinar

MCQs

Total Questions : 14 | Page 2 of 2 pages
Question 11. What is the time complexity of the above recursive implementation of binary search?
  1.    O(n)
  2.    O(2n)
  3.    O(logn)
  4.    O(n!)
 Discuss Question
Answer: Option C. -> O(logn)


The time complexity of the above recursive implementation of binary search is O(logn).


Question 12. Consider the following code:#includeint recursive_sum(int n){      if(n == 0)        return 0;      return ________;}int main(){    int n = 5;    int ans = recursive_sum(n);    printf("%d",ans);    return 0;}Which of the following lines is the recurrence relation for the above code?
  1.    (n "“ 1) +recursive_sum(n)
  2.    n + recursive_sum(n)
  3.    n + recursive_sum(n "“ 1)
  4.    (n "“ 1) + recursive_sum(n "“ 1)
 Discuss Question
Answer: Option C. -> n + recursive_sum(n "“ 1)


The recurrence relation for the above code is: n + recursive_sum(n “ 1).


Question 13. Consider the following recursive implementation to find the sum of digits of number:#includeint 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;}Which of the following lines should be inserted to complete the above code?
  1.    (n / 10) + recursive_sum_of_digits(n % 10)
  2.    (n) + recursive_sum_of_digits(n % 10)
  3.    (n % 10) + recursive_sum_of_digits(n / 10)
  4.    (n % 10) + recursive_sum_of_digits(n % 10)
 Discuss Question
Answer: Option C. -> (n % 10) + recursive_sum_of_digits(n / 10)


The line "(n % 10) + recursive_sum_of_digits(n / 10) should be inserted to complete the above code.


Question 14. Consider the following recursive implementation used to reverse a string:void recursive_reverse_string(char *s, int left, int right){     if(left < right)     {         char tmp = s[left];         s[left] = s[right];         s[right] = tmp;         _________;     }}Which of the following lines should be inserted to complete the above code?
  1.    recursive_reverse_string(s, left+1, right+1)
  2.    recursive_reverse_string(s, left-1, right-1)
  3.    recursive_reverse_string(s, left+1, right-1)
  4.    recursive_reverse_string(s, left-1, right+1)
 Discuss Question
Answer: Option C. -> recursive_reverse_string(s, left+1, right-1)


The line "recursive_reverse_string(s, left+1, right-1) should be inserted to complete the above code.


Latest Videos

Latest Test Papers