title: How to calculate the order of an algorithm with recursive calls inside a loop
body: <p>I have been doing some examples of calculating the cost recursive algorithms which are inside loops, and this one has me wondering how I could calculate it.</p>
  
  <pre><code>int example(int max) {
      int i  =  1;
      double x  =  0.0;
  
      while ( i &lt;= max ) {
          x  =  calculate (x , i);
          i  = 2 ∗ i ;
      }
  }
  </code></pre>
  
  <p>We know that calculate (int x, int i) is of O(i), and that the order of example should be based on max. </p>
  
  <p>An easier example of this would be the same code with a for(int i = 1;  i &lt;= max; i++) loop, which would make an order on example of O(max^2), but in this case i is multiplied by two on each call. How could the cost be calculated in this case?</p>