Molly S.

asked • 02/15/18

How many calls to mystery are made (including the first call) of mystery(0, 4, 5) when arr = {1, 2, 3, 5, 7}?

Give the following code:

private int[] arr;
public int mystery(int low, int high, int num) {
int mid = (low+high) / 2;
if (low > high) {
return -1;
}
else if (arr[mid] < num) {
return mystery(mid +1, high, num);
}
else if (arr[mid] > num) {
return mystery(low, mid - 1, num);
}
else
return mid;
}
 
How many calls to mystery are made (including the first call) of mystery(0, 4, 5) when arr = {1, 2, 3, 5, 7}?
A) 1
B) 2
C) 3
D) 4
E) 5

1 Expert Answer

By:

Edward A. answered • 02/15/18

Tutor
4.9 (17)

High School Math Whiz Grown Up--I've even tutored my grandchildren

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.