Understanding binary search algorithm
The strategy from the earlier example could be used to create an algorithm. To explain this algorithm, we will use an array sorted in ascending order and search for a target number.
Algorithm
The binary search algorithm searches for a target value in a sorted array by repeatedly dividing the search space in half. It works by comparing the target value with the middle element of the current search range. The algorithm begins by initialising two indices that define the current search range in which the target value may exist.
Liking the course? Check our discounted plans to continue learning.