An Intuitive way of SEARCHING {0|1}— Binary Search

--

Photo by Mitch Lensink on Unsplash

What is Binary Search.

It is a search mechanism or algorithm ,that can be applied only on the Sorted Numbers to find the required numbers index or required number efficiently in logarithmic time complexity. Binary search begins by comparing the middle element of the array with the target value.

If the target value matches the middle element, its position in the array is returned.

If the target value is less than the middle element, the search continues in the lower half of the array.

If the target value is greater than the middle 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. That means we are skipping the half of the elements in the given list , so search becomes faster than usual

What is Binary Search and why do we use it.

Implementation in JAVA

Stay Tuned More Details are coming your Way.

--

--