title: What is the difference of the order of growth of the running time between two code fragments below?
body: <pre class="lang-java prettyprint-override"><code>String s =&quot;&quot;;
  for (int i = 0; i &lt; n; i++) {
      if (StdRandom.bernoulli(0.5)) s += &quot;0&quot;; 
      else                          s += &quot;1&quot;; 
  }
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>StringBuilder sb = new StringBuilder(); 
  for (int i = 0; i &lt; n; i++) {
      if (StdRandom.bernoulli(0.5)) sb.append(&quot;0&quot;); 
      else                          sb.append(&quot;1&quot;);
  }
  String s = sb.toString(); 
  </code></pre>
  <p>I don't understand why the first is quadratic and the second is linear. It's one of the exersizes of the chapter 4 of the book &lt;Computer Science · An Interdisciplinary Approach&gt;.</p>