← Back to Data Structures & Algorithms
Question 432
Finish the Binary Search Middle Step
Finish the Binary Search Middle Step
This NumberList is built from values already in ascending order. binarySearch(int target) declares low and high, loops while low <= high, and narrows the range both ways. Two pieces are missing.
Requirements:
1. Set mid to the middle index of the current low..high range.
2. Make targetIsAbove true exactly when target must sit to the right of mid.
3. Return the index of target, or -1 when it is not in the list.
Do NOT write a main method.Expected Output:
List: 2 4 6 8 10 12 0 5 3 -1
= newline. The output ends with a newline — print one after the last line.
Hints2 available
Sign in to use hintsTopics:
Data Structures & AlgorithmsSorting
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.