Skip to content

Prime-victor/binary-search-one-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

binary-search-one-test

Binary Search β€” One Test Inside Loop

πŸ“Œ Exercise 3-1 (from The C Programming Language)

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.

πŸ—‚οΈ Files

  • binsearch.c β€” Original version
  • binsearch_one_test.c β€” Optimized version
  • main.c β€” Runs both and measures runtime
  • Makefile β€” Easy build

⚑ How to build & run

make
./main

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages