Skip to content

Commit cfc0963

Browse files
committed
Enhance IterativeBinarySearch with null safety and improved documentation
1 parent 89189e5 commit cfc0963

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class BinarySearch implements SearchAlgorithm {
5151
* // notFound will be -1 (element 4 does not exist)
5252
* </pre>
5353
*
54-
* @param <T> The type of elements in the array (must be Comparable)
54+
* @param <T> The type of elements in the array (must be Comparable)
5555
* @param array The sorted array to search in (MUST be sorted in ascending order)
56-
* @param key The element to search for
56+
* @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
5858
*/
5959
@Override
@@ -89,10 +89,10 @@ public <T extends Comparable<T>> int find(T[] array, T key) {
8989
* <p>Time Complexity: O(log n) because we halve the search space each time.
9090
* Space Complexity: O(log n) due to recursive call stack.
9191
*
92-
* @param <T> The type of elements (must be Comparable)
92+
* @param <T> The type of elements (must be Comparable)
9393
* @param array The sorted array to search in
94-
* @param key The element we're looking for
95-
* @param left The leftmost index of current search range (inclusive)
94+
* @param key The element we're looking for
95+
* @param left The leftmost index of current search range (inclusive)
9696
* @param right The rightmost index of current search range (inclusive)
9797
* @return The index where key is located, or -1 if not found
9898
*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public final class IterativeBinarySearch implements SearchAlgorithm {
2727
* Performs iterative binary search on a sorted array.
2828
*
2929
* @param array the sorted array
30-
* @param key the element to search
31-
* @param <T> type of elements (must be Comparable)
30+
* @param key the element to search
31+
* @param <T> type of elements (must be Comparable)
3232
* @return index of the key if found, otherwise -1
3333
*/
3434
@Override

0 commit comments

Comments
 (0)