String s ="";
for (int i = 0; i < n; i++) {
if (StdRandom.bernoulli(0.5)) s += "0";
else s += "1";
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
if (StdRandom.bernoulli(0.5)) sb.append("0");
else sb.append("1");
}
String s = sb.toString();
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 <Computer Science · An Interdisciplinary Approach>.