title: Binary Search with 2 Elements
body: <p>I'm using binary search to find an object in array.
  It works. but, if the array only has 2 objects, and the one I want to find is in the 2nd index, I'm getting -1.</p>
  
  <pre><code>mid = (low + high) / 2;
  </code></pre>
  
  <p>mid is getting 0, and then if songName isn't there it's returning -1</p>
  
  <pre><code>public int isSongExist(String songName) {
      int low = 0;
      int high = this.songs.length - 1;
      int mid;
  
      while (low &lt;= high) {
          mid = (low + high) / 2;
  
          if (this.songs[mid].getSongName().compareToIgnoreCase(songName) &lt; 0) {
              low = mid + 1;
          } else if (songs[mid].getSongName().compareToIgnoreCase(songName) &gt; 0) {
              high = mid - 1;
          } else {
              return mid;
          }
      }
      return -1;
  }
  </code></pre>