adplus-dvertising
frame-decoration

Question

Consider the following recursive implementation to find the largest element in an array:
Which of the following lines should be inserted to complete the below code?
int max_of_two(int a, int b)
{
      if(a > b)
        return a;
      return b;
}
int recursive_max_element(int *arr, int len, int idx)
{
      if(idx == len - 1)
      return arr[idx];
      return _______;
}

a.

max_of_two(arr[idx], recursive_max_element(arr, len, idx))

b.

recursive_max_element(arr, len, idx)

c.

max_of_two(arr[idx], recursive_max_element(arr, len, idx + 1))

d.

recursive_max_element(arr, len, idx + 1)

Answer: (c).max_of_two(arr[idx], recursive_max_element(arr, len, idx + 1))

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Consider the following recursive implementation to find the largest element in an array: Which of the following lines should be inserted to complete the below code?