MCQs
All of the mentioned can be realized by binary search.
T(n) = T(n/2) + 1, Using the divide and conquer master theorem.
If the step size is 1, it becomes a linear search, if it is n, we reach the end of the list in just on step, if it is n/2, it becomes similar to binary search, therefore the most efficient step size is found to be sqrt(n).
After finding the correct block of k elements, a sequential search is performed in this block.
Although ordered linear search is better than unordered when the element is not present in the array, the best and worst cases still remain the same, with the key element being found at first position or at last position.
Every time check the key with the array value at first index, if it is not equal then call the function again with an incremented first index.
Tracing with the above code, comparison #1: i=4, comparison #2: i=7, comparison #3: i=8
The print statement is executed only when the items are equal and their indices are not.
This gives a very slight improvement as you are skipping the first k elements.
Find the 'mid', check if it equals the key, if not, continue the iterations until low