Find the given key from the table by using binary search.

Drag the visited keys into the list below. Visited keys are the keys used as the value of mid.

Some addditional problems.

    int binarySearch( int table[], int x)
    {
        int low = 0;
        int high = a.length - 1;
        int mid;

        while( low <= high )
        {
            mid = (low + high) / 2;

            if( table[mid] < x)
                low = mid + 1;
            else if(table[mid] > x)
                high = mid - 1;
            else
                return mid;
        }

        return -1;     // Not found
    }