![cstevenson](/avatars/1999.jpg)
cstevenson
26.08.2021 •
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
Solved
Show answers
More tips
- F Food and Cooking Delicious and Simple Fillings for Pies...
- H Health and Medicine How to Help Men Gain Weight?...
- A Auto and Moto Discovering the Leader: What is the Most Expensive Car in the World?...
- H Health and Medicine Hangover: How to Get Rid of It Quickly?...
- S Style and Beauty How to Choose the Right Fur Coat and Avoid Regrets?...
- C Computers and Internet How to Create a Folder on Your iPhone?...
- G Goods and services How to sew a ribbon: Tips for beginners...
- F Food and Cooking How to Make Mayonnaise at Home? Secrets of Homemade Mayonnaise...
- C Computers and Internet Which Phone is Best for Internet Surfing?...
- F Food and Cooking Everything You Need to Know About Pasta...
Answers on questions: Computers and Technology
- C Computers and Technology Who wants to chat and is very bored...
- C Computers and Technology The controls the execution of the cpu as a whole. it fetches instructions from memory, decodes them, and makes the perform the required operations. word bank: memory unit control...
- C Computers and Technology Aresearch team is studying parallel computing. they want to run parallel processes without having to use multiple processors. how can this be done? a. by using cache b. by using...
- C Computers and Technology Assume a communication system uses five protocol layers. If the application program using this communication system creates a message of 100 bytes and each layer adds a header...
- H Health How do you calculate newtons...
- C Computers and Technology Summary of the total cost of maintaining your home office has the only companions space for 830 wrecker company compare discuss with the option of a building at work that include...
- E English Identify lines where the poet makes Casey seem like an epic hero? This is from the story Casey at the bat!...
- E English Text: They had this machine . They had two machines really. One of them slid down into your stomach like a black cobra down an echoing well looking for all the old water and...
- M Mathematics Using the distributive property, rewrite the expression (-2x - 8) (-6) A: 12x - 48 B: 12x - 8 C: -96x D: -2x + 48 E: 12x + 48...
- M Mathematics Plz hurry and DONT give me a link The point (-5, 6) is located in which quadrant? 8 6 4 ND 2 -9 -6 -4 -4-2 2 4 8 8 x -4 -6 -8 O Quadrant ! Quadrant Il 0 Quadrant III Quadrant...
Ответ:
Low-power and short-latency memory access is critical to the performance of chip multiprocessor (CMP) system devices, especially to bridge the performance gap between memory and CPU