title: How to find the number of iterations of binary search algorithm?
body: <p>How I can get the number of iterations of binary search?</p>
  
  <p>This is my code: </p>
  
  <pre><code>int main() 
  {
      int target = 11;
      int N = 10;
      std::vector&lt;int&gt; index;
      int num;
  
      for (int i = 0; i &lt; N; i++) {
          index.push_back(i);
      }
  
      int counter = 0;
      unsigned int M, L = (unsigned int)-1, R = N;
  
      M = (R - L) / 2;  // Assume N is not zero
  
      do {
          int value;
          M = M + L;
          value = index[M];
          if (value &lt; target) L = M; else R = M;
          M = (R - L) / 2;
          counter++;
      } while (M);  // M is the size of the current interval
  
      std::cout &lt;&lt; R &lt;&lt; '\n';
      std::cout &lt;&lt; "counter: " &lt;&lt; counter &lt;&lt; '\n';
  
      system("pause");
  
      return 0;
  }
  </code></pre>
  
  <p>I want to know the number of iterations depending on <code>N</code>.
  I know how this algorithm works but I want the number of iterations 
  represented mathematically.</p>