Search in a Sorted Array
Problem. Find a given value in a sorted array, or say it doesn’t occur in the array.
Rule of Thumb. Write a precise specification.
/* 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)
Rule of Thumb. Find inspiration from experience, e.g., looking up a name in a telephone directory.