Skip to content

Commit 56c31c1

Browse files
authored
docs: improve BinarySearch documentation for better readability
1 parent af1d9d1 commit 56c31c1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,17 @@ else if (comp < 0) {
125125
}
126126
}
127127
}
128+
/**
129+
* Performs Binary Search on a sorted array.
130+
*
131+
* Binary Search works by repeatedly dividing the search interval in half.
132+
* It compares the target value to the middle element of the array.
133+
* If they are not equal, the half in which the target cannot lie is eliminated.
134+
*
135+
* Example:
136+
* Input: arr = [1, 3, 5, 7, 9], target = 5
137+
* Output: Index = 2
138+
*
139+
* Time Complexity: O(log n)
140+
* Space Complexity: O(1)
141+
*/

0 commit comments

Comments
 (0)