Binary Search Step Counter
PROSorting & SearchingBinary Search
1D & 2D Arrays
Write a program that inputs 7 integers which are already sorted in ascending order into an array, then inputs a target value.
Use a binary search with `low` as the first index, `high` as the last index and `mid = (low + high) DIV 2`. Count each time the middle item is examined.
- If the target is found, output the number of steps taken to find it.
- If it is not in the array, output `Not Found`.
For example, with the array 2, 5, 8, 12, 16, 23, 38 and a target of 23, the middle items checked are 12 then 23, so the output is 2.
Example Input
2
5
8
12
16
23
38
23
Example Output
2
0% (0 passed / 0 attempted)