Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 16, Problem 3SA

Explanation of Solution

Binary search algorithm:

The binary search algorithm is used to find an item in an array and the search array should be in the sorted order.

  • The searching is started in the middle of the array.
  • In the searching process, the algorithm finds an item or eliminates half of the array in each comparison.
  • If the search item is less than the middle item, then it eliminates the second half of the array, and it continues to search in the first half of the array.
  • If the search item is greater than the middle item, then it eliminates the first half of the array, and it continues to search in the second half of the array.
  • Once again, it examines the middle and repeats the above steps to find an item.
  • If the middle item is equal to search item, then the searching is stopped...

Blurred answer
Students have asked these similar questions
If a sequential search method is searching for a value that is stored in the last element of a 10,000-element array, how many elements will the search code have to read to locate the value?
In a partially populated array, how do you maintain track of elements with data?
ARRAY RANDOMIZER Create a program that shuffels all the elements present in an array. To shuffle an array, you need to do at least 500 random swaps of any elements in the array given below. Print the shuffled array in the output. {12, 54, 22, 100, -3, 5, 10, -33, 78, 90, 29, -45, 77, -9, 19, 21} Language: CPP

Chapter 16 Solutions

Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning