DEV Community

Cover image for Computer Science 4 Newbies - Understanding Binary Search

Computer Science 4 Newbies - Understanding Binary Search

Duca on August 14, 2023

As instructed by the first lesson of the book Understanding Algorithms, we must create a binary search that uses the "divide to conquer" method to ...
Collapse
 
sjmulder profile image
Sijmen J. Mulder

For large lists the difference really is massive. I implemented the linear scan from your post, the binary search from your post, and the branchless binary search from mhdm.dev/posts/sb_lower_bound/ and when searching a list of 500 million for page 490 ish million, the linear search takes 0.85 seconds while the binary searches take 4 and 1 micro(!) seconds respectively.

Collapse
 
yelldutz profile image
Duca

great! thank you for taking a time to test the code and read the article

Collapse
 
sjmulder profile image
Sijmen J. Mulder

Cheers! Forgot to mention btw that I reimplemented in C but I think that's only relevant for the branchless version.