title: calculate time complexity of square root algorithm
body: <p>I was going through below link <a href="https://stackoverflow.com/questions/1623375/writing-your-own-square-root-function">enter link description here</a> and going through answers I wanted to calculate time complexity of below suggested code. I played with quite a few values and number of steps are hovering between 23 (even for small values) and say 50 for real big values. How should I go about calculating time complexity for below code - Any pointers?</p>
  
  <pre><code>float val, low, high, mid, oldmid, midsqr;
  // Set initial bounds and print heading.
  low = 0; high = mid = val; oldmid = -1;
  
  // Keep going until accurate enough.
  while (fabs(oldmid - mid) &gt;= 0.00001) 
  {
      oldmid = mid;
      // Get midpoint and see if we need lower or higher.
      mid = (high + low) / 2;
      midsqr = mid * mid;
      if (mid * mid &gt; val) 
      {
          high = mid;
          printf("- too high\n");
      }
      else 
      {
          low = mid;
          printf("- too low\n");
      }
  }
  </code></pre>