This exercise improves the classic binary search by reducing the number of tests inside the loop from two to one.
β
Original version:
Checks if x < v[mid] and else if x > v[mid] on each loop.
β
Optimized version:
Uses only if (x <= v[mid]) inside the loop and checks equality only once outside.
binsearch.cβ Original versionbinsearch_one_test.cβ Optimized versionmain.cβ Runs both and measures runtimeMakefileβ Easy build
make
./main