title: Iterative binary search with only two comparisons?
body: <p>Adjust the iterative binary search code so that it uses only two comparisons instead of three (in
  the main while loop). *Note: The three comparisons are in the while loop, and two if statements
  within the loop.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int ItBinarySearch(int arr[], int len, int target) {
  
      int first = 0;
      int last = len-1;
  
      while (first &lt;= last){
          // Assert: array is sorted
          int mid = (first+last) / 2;
  
          if (target == arr[mid])
              return 1;
  
          if (target &lt; arr[mid])
              last = mid-1;
  
          else first = mid+1;
      }
      return 0;
  }
  
  int main(void){
      int arr[6]={0,1,2,3,4,5};
      int len=sizeof(arr)/sizeof(arr[0]);
      int target = 4;
      printf("%d\n",ItBinarySearch(arr,len,target));
  }
  </code></pre>