May 2019
Intermediate to advanced
698 pages
17h 21m
English
A generic fast search function is provided through slices as well, called binary_search(). As discussed in Chapter 20, Finding Stuff, a binary search returns the index of an element after closing in on its position by repeatedly choosing a half.
To achieve that, there are two prerequisites that the input slice has to satisfy:
binary_search() cannot check whether the collection that's provided is sorted, which means that if an unordered collection returns the expected result, it can only be coincidental. Additionally, if there are multiple elements with the same value, any of those can be the result.
Other than using the implicitly provided comparison function (by implementing ...
Read now
Unlock full access