title: divide and conque binary search in C
body: <p>I'm trying to make a divide and conquer version of binary search, but one that divides the array to two subarrays and search similar to merging in merge sort, the reason I want to do that becuase I want to use it in cilk, but I have to make it that way.
  Here is the code I wrote, which seems to have something wrong with it as its returning -1 to valid key values.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "BinarySearch.h"
  
  int main () {
      int a[] = {0,1,2,3,4,5,6,7,8,9};
      int index = binarySearch(a, 0, 9, 7);
      printf("%i", index);
  
      return 0;
  }
  
  int binarySearch (int* A, int first, int last, int key) {
      if (last &lt; first)
          return -1;
      else {
          int mid = (last + first) / 2;
  
          if (A[mid] == key)
              return mid;
  
          int x, y;
          x = binarySearch(A, first, mid - 1, key);
          y = binarySearch(A, mid + 1, last, key);
  
          if (x == -1 &amp;&amp; y == -1)
              return -1;
          else if (x == -1 &amp;&amp; y != -1)
              return y;
          else
              return x;
      }
  }
  </code></pre>