Write Binary Search From Scratch
mediumQuestion 454This NumberList is built from values that are already in ascending order, so it can be searched by halving the range instead of scanning it.
Requirements:
1. Write binarySearch(int target): return the index where target sits, or -1 when it is not in the list.
2. Write contains(int target) as a one-line wrapper that calls binarySearch. Do not search the array a second time.
Do NOT write a main method.
Expected output
0 6 3 -1 true false
= newline. The output ends with a newline, so print one after the last line.
Hints4 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.