
The binary search
elements are in order. This algorithm is analogous to the following approach to finding a
name in a telephone book.
a. Open the book in the middle and look at the middle name on the page.
b. b. If the middle name isn't the one, you're looking for, decide whether it comes
before or after the name you want.
c. Take the appropriate half of the section of the book you were looking in and repeat
these steps until you land on the name.
1. Let the bottom be the subscript of the initial array element.
2. Let the top be the subscript of the last array element.
3. Let found be false.
4. Repeat as long as the bottom isn't greater than the top and the target has not
been found.
5. Let middle be the subscript of the element halfway between bottom and top.
6. If the element in the middle is the target
7. Set found to true and index to middle. else if the element in the middle is larger
than the target
8. Let the top be middle - 1. else 9. Let bottom be middle +1
Develop a recursive binary search algorithm and write and test a function
binary_srch that implements the algorithm for an array of integers
Use the following example to write your code.
#include <stdio.h>
#include <string.h>
// Function to perform binary search on an array of names
int binary_srch(const char* arr[], const char* target, int
bottom, int top) {
//Your code Here
}
int main() {
const char* names[] = {"Alice", "Bob", "Charlie", "David",
"Eve", "Frank", "Grace", "Hannah", "Isabel", "Jack"};
char target[100];
printf("Enter the name to search: ");
scanf("%s", target);
//Your code here
return 0;
}

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

- How does one go about keeping track of items that have data while working with an array that is only half populated?arrow_forwardThe following program is supposed to let the end-user enters 10 numbers in a one dimensional array. The program must then check the input numbers in the following order and way: 1f the input number is a negative one, the program should multiply that number by (5), and return the number of negative elements in the array. 2. if the input number is a positive one, the program should multiply that number by (2), and return the number of positive elements in the array. 3. if the input number is a zero, the program should return the number of zeros in the array The program code is given below with some missing code. You are required to write the missing code ONLY in order to make the program complete. Sample Input/Output Enter 10 numbers in the array -8 -16 16 80 2 12 -12 -2 0 -40 -80 32 16 0 4 24 -60 -10 0 The number of negative elements is: 4 The number of positive elements is: 4 The number of zeros is: 2 dinclude using namespace std; int main() int input[10], i, negative-0, positive-0,…arrow_forwardPrint true if the user-entered array contains, somewhere, three increasing adjacent. Programming language: Javaarrow_forward
- Suppose an array has n elements. This _____ sorts to sort and array works as follows: Find the smallest element and place it in the first position. Then find the smallest of the remaining n-1 elements and place it in the second position. Repeat on n-2 elements, n-3 elements, ..., until the array is sorted.arrow_forwardInput a list of employee names and salaries and store them in parallel arrays. End the input with a sentinel value. The salaries should be floating point numbers Salaries should be input in even hundreds. For example, a salary of 36,510 should be input as 36.5 and a salary of 69,030 should be entered as 69.0. Find the average of all the salaries of the employees. Then find the names and salaries of any employee who's salary is within 5,000 of the average. So if the average is 30,000 and an employee earns 33,000, his/her name would be found. Display the following using proper labels. i need to do this in raptor.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





