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, 24.06.2019 07:00
Selective is defined as paying attention to messages that are consistent with one’s attitudes and beliefs and ignoring messages that are inconsistent.
Answers: 1
question
Computers and Technology, 25.06.2019 02:30
How to delete a question in
Answers: 2
question
Computers and Technology, 25.06.2019 07:00
The graph shows the number of chapters sarah read in a book each day of a week
Answers: 1
question
Computers and Technology, 25.06.2019 07:50
Assignment: permutations use the permutation formula   r ! ! n n p nr   to solve each problem. be sure to show all work leading to your answer. part i: solve real-world permutation problems choose any four (4) of the following five problems to solve. for each problem a) show how the permutation formula can be used to find the answer and b) write a sentence to explain the meaning of the answer for the situation. 1. to register for online banking services at a local credit union, you need to select a four-digit personal identification number, or pin code. the digits cannot be repeated. how many ways are there to arrange four digits out of the numerals 0 through 9 to create a code?
Answers: 3
You know the right answer?
Search for the character Z using the binary search algorithm on the following array of characters: A...
Questions
question
Spanish, 14.01.2021 07:30
question
Mathematics, 14.01.2021 07:30
question
Mathematics, 14.01.2021 07:30
question
Mathematics, 14.01.2021 07:30
question
History, 14.01.2021 07:30