Computers and Technology

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

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:00, alyssacyamamoto8050
Budgets you to do all of the following expect a) send frivolously b) avoid over spending c) gain financial independence d) examine your priorities and goals
Answers: 2
image
Computers and Technology, 23.06.2019 05:30, savyblue1724707
Sally is editing her science report about living things. she needs to copy a paragraph from her original report. order the steps sally needs to do to copy the text to her new document.
Answers: 1
image
Computers and Technology, 23.06.2019 17:00, kyleemarie2003
Companies that implement and apply an information system effectively can create
Answers: 1
image
Computers and Technology, 23.06.2019 20:30, summerhumphries3
What are some settings you can control when formatting columns?
Answers: 1
Do you know the correct answer?
Search for the character Z using the binary search algorithm on the following array of characters: A...

Questions in other subjects:

Konu
English, 19.11.2020 23:30
Konu
Chemistry, 19.11.2020 23:30
Konu
Mathematics, 19.11.2020 23:30
Konu
Mathematics, 19.11.2020 23:30