✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
What is the time and space complexity of this function?
int g(int arr[], int n, int target) {
int low = 0, high = n - 1;
while (low <= high) {
int mid = (low + high) / 2;
if (arr[mid] == target) {
return mid;
} else if (arr[mid] < target) {
low = mid + 1;
} else {
high = mid - 1;
}
}
return -1;
}