How does this implementation of binary search work?
<pre><code>% java BinarySearch 1.txt &lt; 2.txt
</code></pre>

<p>If I have two text files (1.txt and 2.txt), where 2.txt contains values not in 1.txt, how does the binary search work in giving us these values?  If the arguments to <code>BinarySearch</code> are a key and a sorted array, I don't see how this applies.</p>

<p>Here is the code for the binary search:</p>

<pre><code>import java.util.Arrays;

public class BinarySearch {

    // precondition: array a[] is sorted
    public static int rank(int key, int[] a) {
        int lo = 0;
        int hi = a.length - 1;
        while (lo &lt;= hi) {
            // Key is in a[lo..hi] or not present.
            int mid = lo + (hi - lo) / 2;
            if      (key &lt; a[mid]) hi = mid - 1;
            else if (key &gt; a[mid]) lo = mid + 1;
            else return mid;
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] whitelist = In.readInts(args[0]);

        Arrays.sort(whitelist);

        // read key; print if not in whitelist
        while (!StdIn.isEmpty()) {
            int key = StdIn.readInt();
            if (rank(key, whitelist) == -1)
                StdOut.println(key);
        }
    }
}
</code></pre>

<p>According to Wikipedia, and from what I'd understood: A binary search or half-interval search algorithm finds the position of a specified value (the input "key") within a sorted array.</p>

<p>So how is it working to find uncommon values in two text files?</p>
