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