Search for the character Z using the binary search algorithm on the following array of characters: A DHJLNPRZ
Search for the character Z using the binary search algorithm on the following array of characters: A DHJLNPRZ
Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 19RQ
Related questions
Question
java
![Search for the character Z using the binary search algorithm on the
following array of characters: ADHJLNPRZ
For each iteration of binary search use a table similar to 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 of the region of the array that is still being searched, and (d) the character-to-
character number of comparisons made during the search (line 09 and line 11 of the Binary
Search algorithm).
01 public static int binarySearch (char [] a, char target) {
02
03
int left = 0;
04
int right = a.length - 1;
05
06
while ( left <= right {
07
int middle = ( left + right ) / 2;
if ( a[middle]
08
09
== target ) {
10
return middle;
} else if ( target < a[middle] ) {
11
right = middle - 1;
} else {
12
13
14
left = middle + 1;
15
}
16
}
return -1; // target not found
18 }
17
Iteration
Left | Right | Middle | Number of Comparisons
1
3
Enter your answer here](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd25e8515-f086-4ca9-99e8-c0ef854763b7%2F7cd72cc1-35c8-4123-a111-209e5d2c881a%2Fkhd8yhh_processed.png&w=3840&q=75)
Transcribed Image Text:Search for the character Z using the binary search algorithm on the
following array of characters: ADHJLNPRZ
For each iteration of binary search use a table similar to 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 of the region of the array that is still being searched, and (d) the character-to-
character number of comparisons made during the search (line 09 and line 11 of the Binary
Search algorithm).
01 public static int binarySearch (char [] a, char target) {
02
03
int left = 0;
04
int right = a.length - 1;
05
06
while ( left <= right {
07
int middle = ( left + right ) / 2;
if ( a[middle]
08
09
== target ) {
10
return middle;
} else if ( target < a[middle] ) {
11
right = middle - 1;
} else {
12
13
14
left = middle + 1;
15
}
16
}
return -1; // target not found
18 }
17
Iteration
Left | Right | Middle | Number of Comparisons
1
3
Enter your answer here
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,

Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning

Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning