Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

The binary search algorithm that follows may be used to search an array when the 
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;
}

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education