Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/com/thealgorithms/searches/BinarySearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Loading