Everyone knows Binary Search. It’s an algorithm that needs a sorted array to work. However, it is pretty ineffective when coming to certain tasks, like this one:
1 1 2 3 5 8 11
Find 5
The algorithm will go through 3 iterations to find the given number, like this:
1 1 2 3 5 8 11
^
1 1 2 3 5 8 11
^
1 1 2 3 5 8 11
^
However, what if I told you that I could do it in 2?
By using a simple tweak to the algorithm, I can. I tweaked it to be both a Binary search and a Linear search. Instead of magically jumping to the next number we need to search, we instead use linear search to get to the new number. By using this new algorithm, we can do it in 2.