title: Most appropriate run-time formula in terms of primitive operations needed for input of size n
body: <p>For the following block of code, select the most appropriate run-time formula in terms of primitive operations needed for input of size n:</p>
  
  <p>When resolving from inside out, i get:</p>
  
  <p>inner loop = 3n+1</p>
  
  <p>main loop + inner loop = 3 + (3n +1) + logn = 4 + 3n + logn</p>
  
  <p>extra steps + all loops = 4 + n(4 + 3n + logn) = 4 + 4n + 3n2 + logn</p>
  
  <p>This is the code to analyze:</p>
  
  <pre><code>def rate(n):
      total= 0
      i = 1
      while i &lt; n:
          j = 0
          while j &lt; n:
              total= i * j + total
              j = j + 1
          i = i * 2
      return total
  </code></pre>
  
  <p>and the answer is supposed to be --> f(n) = 4 + 4log(n)  + log(n)*(3n)</p>