Skip to content

Commit b9c25a8

Browse files
docs: add edge cases to BinarySearch documentation
1 parent 9cd54ee commit b9c25a8

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/main/java/com/thealgorithms/searches/BinarySearch.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ class BinarySearch implements SearchAlgorithm {
5555
* @param array The sorted array to search in (MUST be sorted in ascending order)
5656
* @param key The element to search for
5757
* @return The index of the key if found, -1 if not found or if array is null/empty
58+
*
59+
* <p><strong>Edge Cases:</strong>
60+
* <ul>
61+
* <li>Null array → returns -1</li>
62+
* <li>Empty array → returns -1</li>
63+
* <li>Null key → returns -1</li>
64+
* <li>Element not found → returns -1</li>
65+
* <li>Single element array → works correctly</li>
66+
* <li>Duplicate elements → may return any one valid index</li>
67+
* </ul>
5868
*/
5969
@Override
6070
public <T extends Comparable<T>> int find(T[] array, T key) {

0 commit comments

Comments
 (0)