Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 8.2, Problem 8.3CP
Program Plan Intro
Binary search:
- Binary search is a smart search process that searches for the particular element that is present in the array from the middle towards the left or right until the search element is found.
- The search element is searched from the middle as the elements present in the array needs to present in the sorted order.
- If the search element is larger it will search towards the right of the array.
- If the search element is smaller it will search towards the left of the array.
- The search continues in a narrow way that it searches for the quarter of the array until there are no values left in the array to search or compare.
- The search of the target element is made in the smart way it eliminates a portion of array based on the given element as the array is sorted.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
What is the maximum number of elements that will be inspected if a sequential search of 4000 names is performed?
Let N be an unordered array of integers. The maximum number of compares required to find the minimum value is N.
Select one
True or False
Complete the following table by calculating the average and maximum number of comparisons the linear search will perform, and the maximum number of comparisons the binary search will perform.
Chapter 8 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 8.2 - Prob. 8.1CPCh. 8.2 - Prob. 8.2CPCh. 8.2 - Prob. 8.3CPCh. 8.2 - Prob. 8.4CPCh. 8 - Prob. 1RQECh. 8 - If a linear search function is searching for a...Ch. 8 - Prob. 3RQECh. 8 - A binary search function is searching for a value...Ch. 8 - What is the maximum number of comparisons that a...Ch. 8 - Prob. 6RQE
Ch. 8 - Why is the selection sort more efficient than the...Ch. 8 - Prob. 8RQECh. 8 - The __________ search algorithm repeatedly divides...Ch. 8 - Prob. 10RQECh. 8 - The ____________ search algorithm requires that...Ch. 8 - If an array is sorted in ______________ order, the...Ch. 8 - If an array is sorted in _____________ order, the...Ch. 8 - Prob. 14RQECh. 8 - Prob. 15RQECh. 8 - Prob. 16RQECh. 8 - T F The maximum number of comparisons performed by...Ch. 8 - Prob. 18RQECh. 8 - Charge Account Validation Write a program that...Ch. 8 - Lottery Winners A lottery ticket buyer purchases...Ch. 8 - Lottery Winners Modification Modify the program...Ch. 8 - Charge Account Validation Modification Modify the...Ch. 8 - Rainfall Statistics Modification Modify the...Ch. 8 - String Selection Sort Modify the selectionSort...Ch. 8 - Binary String Search Modify the binarySearch...Ch. 8 - Search Benchmarks Write a program that has an...Ch. 8 - Sorting Benchmarks Write a program that uses two...Ch. 8 - Sorting Orders Write a program that uses two...Ch. 8 - Using FilesString Selection Sort Modification...
Knowledge Booster
Similar questions
- What is the procedure for doing a selective sort on an array of elements?arrow_forwardLet N be an unordered array of integers. The maximum number of compares required to find the minimum value is N Select one: OTrue OFalsearrow_forwardIf N represents the number of elements in a list, then searching for an element in a sorted array-based list takes no less than O(N) time. True Falsearrow_forward
- Binary search will perform at most ( ) comparisons on a sorted array of 256 elements. Group of answer choices 512 256 9 8arrow_forwardUsing binary search, if looking for 23 in the following list, what are the numbers that will be compared with 23? (Mid index is the 3th element if there are 6 elements in the array) 8 10 14 20 27 30 36 39 43 51 O a. 25, 10, 14 O b. 30, 14, 27, 20 O c. 27, 10, 14, 20 O d. The element is not on the listarrow_forwardUsing binary search, if looking for 23 in the following list, what are the numbers that will be compared with 23? (Mid index is the 3th element if there are 6 elements in the array) 8 10 14 20 27 30 36 39 43 51 O a. 25, 10, 14 O b. 30, 14, 27, 20 O c. 27, 10, 14, 20 Od. The element is not on the listarrow_forward
- Data Structure & Algorithm: Here is an array with exactly 15 elements:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15Suppose that we are doing a serial search for an element. Circle any elements that will be found by examining two or fewer numbers from the array.arrow_forwardThe element being searched for is not in an array of 100 elements. What is the maximum number of comparisons needed in a sequential search to determine that the element is not there if the elements are completely unsorted?arrow_forwardLet N be an unordered array of integers. The maximum number of compares required to find the minimum value is N-1. [True/False]arrow_forward
- السؤال sequential search: what is the running time of the best case to search if all the elements of an array are equal ? الاجابات O(1) O(n) O(n^2) n log narrow_forwardList all the steps used to search for 18 in the sequence 1, 2, 4, 8, 10, 12, 18, 20, 22. Be sure to show EVERY step. A. linear search B. binary search Use the following array and indices in your answer: Array: 1 2 4 8 10 12 18 20 22 Index: 1 2 3 4 5 6 7 8 9arrow_forwardWith bubble sort, what is the maximum number of comparisons if there are 5 elements in array x? 10 25 2 5arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education