Question: The function depicted below searches for a given value x in the sorted array arr- What is the worst-case time complexity of the function? (4

 The function depicted below searches for a given value x in
the sorted array arr- What is the worst-case time complexity of the

The function depicted below searches for a given value x in the sorted array arr- What is the worst-case time complexity of the function? (4 marks) 1 int function(int arr[], int i, int r, int x){ 2 if (r >= 1) { 3 int mid = 1 + (r - 1) / 2; 4 if (arr[mid] == x) 5 return mid; 6 if (arr[mid) > x) return function(arr, l, mid - 1, x); return function(arr, mid + 1, r, x); 9 } 10 return -1; 11 } 7 8 The function depicted below searches for a given value x in the sorted array arr. Under what condition can the time complexity of function be described as constant? 1 int function(int arr[], int 1, int r, int x){ 2 if (r >= 1) { > 3 int mid = 1 + (r - 1) / 2; if (arr[mid) x) return mid; if (arr(mid) > x) return function(arr, 1, mid - 1, x); return function(arr, mid + 1, r, x); 9 } } return -1; 11 } 8 10

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!