I always thought the complexity of:
1 + 2 + 3 + ... + n is O(n), and summing two n by n matrices would be O(n^2).
But today I read from a textbo
So my guess is that this is actually a reference to Cracking the Coding Interview, which has this paragraph on a StringBuffer implementation:
On each concatenation, a new copy of the string is created, and the two strings are copied over, character by character. The first iteration requires us to copy
xcharacters. The second iteration requires copying2xcharacters. The third iteration requires3x, and so on. The total time therefore isO(x + 2x + ... + nx). This reduces toO(xn²). (Why isn't itO(xnⁿ)? Because1 + 2 + ... nequalsn(n+1)/2or,O(n²).)
For whatever reason I found this a little confusing on my first read-through, too. The important bit to see is that n is multiplying n, or in other words that n² is happening, and that dominates. This is why ultimately O(xn²) is just O(n²) -- the x is sort of a red herring.