May 2017
Intermediate to advanced
340 pages
8h 16m
English
Consider the following image. We have an array with repetitive items. If we try to find the first appearance of 2 from the array, binary search algorithm from the last section will give us the fifth element. However, from the following image, we can see clearly it is not the fifth element; instead, it is the second element, which is the correct answer. So, a modification is required in our binary search algorithm. The modification will be a repetitive searching until we reach the first appearance:

Here is the modified solution using iterative approach:
function repetitiveBinarySearch(array $numbers, ...
Read now
Unlock full access