Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage examples of binary search

I just realized that in my 4+ years of Java programming (mostly desktop apps) I never used the binary search methods in the Arrays class for anything practical. Not even once. Some reasons I can think of:

  1. 100% of the time you can get away with linear search, maps or something else that isn't binary search.
  2. The incoming data is almost never sorted, and making it sorted requires an extra sorting step.

So I wonder if it's just me, or do a lot of people never use binary search? And what are some good, practical usage examples of binary search?

like image 720
python dude Avatar asked Sep 05 '26 16:09

python dude


1 Answers

On the desktop, you're probably just dealing with the user's data, which might not be all that big. If you are querying over very large datasets, shared by many users, then it can be a different matter. A lot of people don't necessarily deal with binary search directly, but anyone using a database is probably using it implicitly. If you use AppEngine, for example, datastore queries almost certainly use binary search.

like image 82
Michael Aaron Safyan Avatar answered Sep 07 '26 07:09

Michael Aaron Safyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!