Binary Search
Implementations
1. Standard Binary Search
// Binary_Search returns the index of target if found, -1 otherwise
func Binary_Search(arr []int, target int) int {
left := 0
right := len(arr) - 1
for left <= right {
mid := left + (right-left)/2
if arr[mid] == target {
return mid
}
if arr[mid] < target {
left = mid + 1
} else {
right = mid - 1
}
}
return -1
}2. Lower Bound
3. Upper Bound
Example Usage
Algorithm Description
Time Complexity: O(log n)
Space Complexity: O(1)
Characteristics
Advantages
Disadvantages
Related LeetCode Problems
Easy
Medium
Hard
Practice Tips
Common Variations
Resources
Last updated