From 56c31c1315c3054795584ed66099a6e1a2760d2d Mon Sep 17 00:00:00 2001 From: AbhiramSakha <143825001+AbhiramSakha@users.noreply.github.com> Date: Sat, 21 Mar 2026 08:28:01 +0530 Subject: [PATCH] docs: improve BinarySearch documentation for better readability --- .../com/thealgorithms/searches/BinarySearch.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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) + */