diff --git a/src/main/java/com/thealgorithms/searches/BinarySearch.java b/src/main/java/com/thealgorithms/searches/BinarySearch.java index 7a5361b280ea..caf924eb87a9 100644 --- a/src/main/java/com/thealgorithms/searches/BinarySearch.java +++ b/src/main/java/com/thealgorithms/searches/BinarySearch.java @@ -125,3 +125,17 @@ else if (comp < 0) { } } } +/** + * Performs Binary Search on a sorted array. + * + * Binary Search works by repeatedly dividing the search interval in half. + * It compares the target value to the middle element of the array. + * If they are not equal, the half in which the target cannot lie is eliminated. + * + * Example: + * Input: arr = [1, 3, 5, 7, 9], target = 5 + * Output: Index = 2 + * + * Time Complexity: O(log n) + * Space Complexity: O(1) + */