subject

Consider the following method, which implements a recursive binary search. /** Returns an index in arr where target appears, if target appears
* in arr between arr[low] and arr[high], inclusive;
* otherwise, returns -1.
* Precondition: arr is sorted in ascending order.
* low >= 0, high < arr. length, arr. length > 0
*/
public static int binarySearch(int[] arr, int low, int high, int target)
{
if (low > high)
{
return -1;
}
int middle = (low + high) / 2;
if (target == arr[middle])
{
return middle;
}
else if (target < arr[middle])
{
return binarySearch(arr, low, middle - 1, target);
}
else
{
return binarySearch(arr, middle + 1, high, target);
}
}
The following code segment appears in a method in the same class as binarySearch.

int[] arr = {2, 3, 12, 34, 54};
int result = binarySearch(arr, 0, arr. length - 1, 5);
If the first call to binarySearch is the call in the code segment above, with low = 0 and high = 4, which, if any, of the following shows the values of low and high when binarySearch is called for the third time?

low = 0, high = 1
A

low = 0, high = 2
B

low = 1, high = 1
C

low = 2, high = 1
D

The method returns to the calling code segment before the third call to binarySearch.
E

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:30, jennyrr9021
This isn’t really school related, but like where the heck can you find manga, to read to where you don’t have to pay money, for points? my friend wants me to read bj alex, and i can’t find it anywhere for free.
Answers: 2
image
Computers and Technology, 22.06.2019 16:20, mandy9386
Consider the following statements, then select one of the answers below: the signal() function shown below registers "sig_handler()" as the signal handler function for the sigkill signal, without the complexity of using when the sigkill signal is sent to a process running this code, by a user typing "kill -kill ", where the correct process id is used for to target the process, sig_handler() will be executed.
Answers: 1
image
Computers and Technology, 23.06.2019 01:40, littlebirdd987
You have a linux system that has a 1000gb hard disk drive, which has a 90gb partition containing an ext4 filesystem mounted to the / directory and a 4gb swap partition. currently, this linux system is only used by a few users for storing small files; however, the department manager wants to upgrade this system and use it to run a database application that will be used by 100 users. the database application and the associated data will take up over 200gb of hard disk space. in addition, these 100 users will store their personal files on the hard disk of the system. each user must have a maximum of 5gb of storage space. the department manager has made it very clear that this system must not exhibit any downtime as a result of hard disk errors. how much hard disk space will you require, and what partitions would you need to ensure that the system will perform as needed? where would these partitions be mounted? what quotas would you implement? what commands would you need to run and what entries to /etc/fstab would you need to create? justify your answers.
Answers: 3
image
Computers and Technology, 23.06.2019 09:30, shadowsnake
Write a function called checkfactor that takes two arrays of positive numbers, firstnumberrow and secondnumberrow. checkfactor checks if the first entry in firstnumberrow is divisible by the first entry in secondnumberrow, and performs the same operation on the next array elements until all entries have been checked. all the numbers are positive and the number of entries in the arrays are the same. the function should return the identified divisible numbers in two row arrays named firstdivisible and seconddivisible. restrictions: branches or loops should not be used. the code must use the internal mod and logical functions. hint: the mod function should be used to determine if two numbers are divisible. ex: for num1 and num2 if mod(num1,num2) is 0, then the two numbers are divisible. this is matlab
Answers: 2
You know the right answer?
Consider the following method, which implements a recursive binary search. /** Returns an index in...

Questions in other subjects:

Konu
Mathematics, 23.07.2019 17:00