Bifalgorithm post
Binary search in under 60 seconds. Binary search is a search algorithm used to find a value within an already sorted array. It works by continually halving the subarray that it is considering until the value is found or it is determined that it does not exist in the array. To achieve this, it maintains two pointers, a left pointer and a right pointer from which the middle position of the subarray can be calculated. We can check this middle position against the value we are searching for to determine if it is the same, higher or lower. When sorted in ascending order, if the middle position is lower than the value we are looking for, we know that the value, if it exists, must be in the subarray to the right of the middle value. Similarly, if it is greater, the value must be in the left subarray if it exists. Of course, if it is the same value, then we have found it and can return. We continue these previous steps, moving the left or right pointer to the beginning or end of the next subarray respectively, until either the value we are looking for becomes the middle position and is found, or there is nothing left to search. Since each subarray is halved until termination, this algorithm has a time complexity of O log n time.
Binary search in under 60 seconds. Binary search is a search algorithm used to find a value within an already sorted array. It works by continually halving the…
Ideas in this flowchart
- Binary Search
- Search Algorithm
- Find Value in Sorted Array
- Process
- Halve Subarray
- Use Pointers
- Calculate Middle Position
- Compare Middle to Target
- Middle < Target
- Search Right Subarray
- Middle > Target
- Search Left Subarray
- Middle = Target
- Value Found
- Time Complexity
- O(log n)