title: Efficient binary-search
body: <p>Out of the two different implementation of binary-search, which one is more efficient and why?</p>
  
  <p>In general binary-search divide a sorted array to two, compare the target entry with operator &lt; or > against the two divided part of array, and keep iterating until finished or found the target entry.</p>
  
  <pre><code>int a[8] = {1, 3, 4, 5, 7, 8, 9, 11};
  </code></pre>
  
  <p>1.</p>
  
  <pre><code>while ( size &gt; 1)
  {
      mid = low + (size/2);
      if (a[mid] &gt; find)
      {
         size = mid - low;
      }
      else
      {
          size = size - (mid - low);
          low = mid;
      }
  }
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>while (low &lt;= size)
  {
      mid = (low + size)/2;
      if (a[mid] &lt; find)
      {
          low = mid + 1;
      }
      else if (a[mid] &gt; find)
      {
          size = mid - 1;
      }
      else
      {
          break;
      } 
  }
  </code></pre>
  
  <p>While searching 6, the first one, iterate as, </p>
  
  <pre><code>mid = 4 size = 4 low = 0
  mid = 2 size = 2 low = 2
  mid = 3 size = 1 low = 3
  5
  </code></pre>
  
  <p>and the second one does one iterate more and taking next entry.</p>
  
  <pre><code>mid = 4 size = 3 low = 0
  mid = 1 size = 3 low = 2
  mid = 2 size = 3 low = 3
  mid = 3 size = 3 low = 4
  7
  </code></pre>
  
  <p>Which one is efficient?</p>