public int binarySearch(int[]array, int num) { int low = 0; //low range int high = array.length -1; //high range int mid; //mid range while () //while low is less than or equal to high { mid = ; //set middle range to be (low + high) /2 if () { //if the array in the middle range = input number //return mid range } else if () { //if the array in the middle range > input number //set the high value to be the mid value minus 1 } else { //set low value to be mid value plus one } } //return -1 here because that would mean that the number is not found in the loop }
public int binarySearch(int[]array, int num) { int low = 0; //low range int high = array.length -1; //high range int mid; //mid range while () //while low is less than or equal to high { mid = ; //set middle range to be (low + high) /2 if () { //if the array in the middle range = input number //return mid range } else if () { //if the array in the middle range > input number //set the high value to be the mid value minus 1 } else { //set low value to be mid value plus one } } //return -1 here because that would mean that the number is not found in the loop }
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 29SA
Related questions
Question
public int binarySearch(int[]array, int num) {
int low = 0;
//low range
int high = array.length -1; //high range
int mid; //mid range
while () //while low is less than or equal to high
{
mid = ; //set middle range to be (low + high) /2
if () { //if the array in the middle range = input number
//return mid range
}
else
if () { //if the array in the middle range > input number
//set the high value to be the mid value minus 1
}
else
{
//set low value to be mid value plus one
}
}
//return -1 here because that would mean that the number is not found in the loop
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
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.Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage