Skip to content

Commit c9c0e2d

Browse files
Add edge cases section in BinarySearch documentation
1 parent 9cd54ee commit c9c0e2d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
* complexity: O(log n) - Element not found or at extreme end - Space complexity: O(1) - Only uses
2424
* a constant amount of extra space
2525
*
26+
* <p><strong>Edge Cases:</strong>
27+
* <ul>
28+
* <li>Empty array: Returns -1</li>
29+
* <li>Null array: Returns -1</li>
30+
* <li>Null key: Returns -1</li>
31+
* <li>Element not found: Returns -1</li>
32+
* <li>Duplicate elements: May return any one valid index of the target</li>
33+
* </ul>
34+
*
2635
* <p>Example Walkthrough: Array: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] Target: 7
2736
*
2837
* <p>Step 1: left=0, right=9, mid=4, array[4]=9 (9 &gt; 7, search left half) Step 2: left=0,

0 commit comments

Comments
 (0)