In which of the below cases will the following code produce a wrong output?

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

In which of the below cases will the following code produce a wrong output?

Post by answerhappygod »

int recursive_binary_search(int *arr, int num, int lo, int hi)
{
if(lo > hi)
return -1;
int mid = (lo + hi)/2;
if(arr[mid] == num)
return mid;
else if(arr[mid] < num)
lo = mid + 1;
else
hi = mid - 1;
return recursive_binary_search(arr, num, lo, hi);
}
a) Array: {0,0,0,0,0,0} Search: -10
b) Array: {1,2,3,4,5} Search: 0
c) Array: {5,4,3,2,1} Search: 1
d) Array: {-5,-4,-3,-2,-1} Search: -1
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!

This topic has 1 reply

You must be a registered member and logged in to view the replies in this topic.


Register Login
 
Post Reply