Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
/**
* Binary search is one of the most popular algorithms The algorithm finds the
* position of a target value within a sorted array
*
* IMPORTANT
* This algorithm works correctly only if the input array is sorted
* in ascending order.
* <p>
* Worst-case performance O(log n) Best-case performance O(1) Average
* performance O(log n) Worst-case space complexity O(1)
Expand All @@ -25,6 +27,9 @@ class BinarySearch implements SearchAlgorithm {
*/
@Override
public <T extends Comparable<T>> int find(T[] array, T key) {
if (array == null || array.length == 0) {
return -1;
}
return search(array, key, 0, array.length - 1);
}

Expand Down