MCQs
Total Questions : 14
| Page 2 of 2 pages
Answer: Option C. -> O(logn)
The time complexity of the above recursive implementation of binary search is O(logn).
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?
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?
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.