into Collectionthis:
Collection
binarySearch(List list, Object key)
Why is binary search not applicable for Set? Why is it just for List?
Set
List
Any specific reason?
Binary search involves a sorted container. The set is either disordered ( HashSet), in which case the binary search cannot be performed or ordered ( TreeSet), in which case its search operation is already effective as a binary search (i.e. O(Log2(N))).
HashSet
TreeSet
O(Log2(N))
Binary search works on an ordered set. The set is not ordered.
, . , .
.
, NavigableSet
The set is unordered and does not contain indexes for the elements contained in it. Therefore, the binarySearch () method, which returns the index of the element, does not make sense.