logo

Crowdly

Browser

Add to Chrome

What is the time and space complexity of this function? int g(int arr[], int n...

✅ 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;  

}

0%
100%
0%
0%
More questions like this

Want instant access to all verified answers on distedu.ukma.edu.ua?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome