subject

Search for the character Z using the binary search algorithm on the following array of characters: A D H J L N P R Z For each iteration of binary search use the table below to list: (a) the left index and (b) the right index of the array that denote the region of the array that is still being searched, (c) the middle point index of the array, and (d) the number of character-to-character comparisons made during the search at lines 8 and 10 of the algorithm at the back of the exam.
public static int binarySearch(char[] a, char target) {
int left = 0; //first index of array
int right = a. length - 1; //last index of array
while (left <= right) {
int middle = (left + right) / 2;
if ( a[middle] == target) {
return middle;
} else if (target < a[middle]) {
right = middle - 1;
} else {
left = middle + 1;
}
}
return -1; //target not found
}
Iteration Left Right Middle Number of Comparisons
1
2
3
4

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 01:00
How can a broadcast station be received through cable and satellite systems?
Answers: 1
question
Computers and Technology, 22.06.2019 22:30
You are new to microsoft certification and want to start out by getting a certification geared around windows 8. what microsoft certification should you pursue?
Answers: 1
question
Computers and Technology, 23.06.2019 07:30
Write a program that inserts the digits of an integer into an array in originalorderfollowed by reverse order. first, promptthe user to enter a positive integer(> 0). determine the number of digits of the integer. create a dynamically allocated integer arrayof a size twice the number of digits.now insert the digits in original order which will occupy half of the array. then, insert the digits in reverse order.finally, output thedigits in thearray.use at least two functions to organize your program.
Answers: 3
question
Computers and Technology, 23.06.2019 09:30
The place where the extended axis of the earth would touch the celestial sphere is called the celestial
Answers: 1
You know the right answer?
Search for the character Z using the binary search algorithm on the following array of characters: A...
Questions
question
English, 20.10.2020 22:01
question
Mathematics, 20.10.2020 22:01
question
Mathematics, 20.10.2020 22:01
question
Mathematics, 20.10.2020 22:01
Questions on the website: 13722360