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
Sorting is a basic issue with arrays in which the goal is to find the target element in the array. Choose from the following options: False
In a partially populated array, how do you maintain track of elements with data?
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?

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
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