5 - Binary Search Algorithm Code in Java

preview_player
Показать описание
Binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array.
Binary search begins by comparing an element in the middle of the array with the target value.
If the target value matches the element, its position in the array is returned. If the target value is less than the element, the search continues in the lower half of the array.
If the target value is greater than the element, the search continues in the upper half of the array.
By doing this, the algorithm eliminates the half in which the target value cannot lie in each iteration.
We have discussed Binary Search algorithm code in Java in this video but logic is common for any programming language.

Time Complexity:
Best Case: O(1)
Average Case: O(log n)
Worst case: O(log n)
Space Complexity: O(1)
Рекомендации по теме
Комментарии
Автор

Thanks Sir ! Wow ! 14 minutes to understand the Binary Search, you deserve a BRAVO ! Thanks

NZIT