Binary Search Algorithm— A Simple Explanation
A Simple Explanation of Binary Search Algorithm with an Example in Python and GO | Karthikeyan Nagaraj
3 min readJan 12, 2023
What is Binary Search?
- Binary search is a search algorithm that finds the position of a target value within a sorted array.
- It is also known as half-interval search, logarithmic search, or binary chop
Working Principle:
- Binary search Algorithm compares the search value to the middle element of the array
- If it is not equal, then the half in which the target cannot lie is eliminated and the search continues on the remaining half
- Again taking the middle element to compare to the target value, and repeating this until the target value is found.
- If the search ends with the remaining half being empty, the target is not in the array.
Steps:
- First, we have to sort the Elements In order to perform a Binary search
- Then we have to check whether the mid value is equal to the value which we are trying to find
- If the mid value is less than the search value then the left side of the array or list is…