From 79cdb98193cb34fa32d9bbad06c21a0d0f356bb3 Mon Sep 17 00:00:00 2001 From: SwaatiR <85189166+SwaatiR@users.noreply.github.com> Date: Sun, 18 Jan 2026 21:31:01 +0530 Subject: [PATCH] Add input validation and clarify sorted array requirement in Binary Search (#7216) Added input validation and clarify sorted array rrequirement in Binary Search --- src/main/java/com/thealgorithms/searches/BinarySearch.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/thealgorithms/searches/BinarySearch.java b/src/main/java/com/thealgorithms/searches/BinarySearch.java index bedad1667..0cac484d5 100644 --- a/src/main/java/com/thealgorithms/searches/BinarySearch.java +++ b/src/main/java/com/thealgorithms/searches/BinarySearch.java @@ -5,7 +5,9 @@ import com.thealgorithms.devutils.searches.SearchAlgorithm; /** * 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. *
* Worst-case performance O(log n) Best-case performance O(1) Average
* performance O(log n) Worst-case space complexity O(1)
@@ -25,6 +27,9 @@ class BinarySearch implements SearchAlgorithm {
*/
@Override
public