Daily bit(e) of C++ | std::binary_search
Daily bit(e) of C++ ♻️225, The O(logn) presence check algorithm on at least partitioned data: std::binary_search.
The std::binary_search is a presence-check algorithm that operates on (at least) a partitioned range (in regards to the searched-for value).
The search algorithm provides O(logn) complexity (number of comparisons); however, if the range does not model random access, the number of iterator increments is linear.
The algorithm is constexpr and provides a range variant (both since C++20) but doesn't have a parallel variant.