Asymptotic Complexity
How many iterations does binary search take?
#iterations 0 1 2 3 4 5 ... log2(N+1)
In contrast, how many iterations does sequential search take in the worst case?
/* Given A[0..N] sorted in non-decreasing order, return the subscript of an occurrence of val in A (if val occurs in A) or N+1 otherwise. */
int find(int[] A, int N, int val)
while (k <= N && val != A[k]) k++;
#iterations 1 2 4 8 16 32 ... N+1