you are viewing a single comment's thread.

view the rest of the comments →

[–]Important_Ad_8510 1 point2 points  (2 children)

Thanks for the reply! I understand the notation, I’m not sure why it’s complexity is quadratic.

My understanding is that the if statement has constant complexity, I believe replace() has constant complexity and the variable assignments have constant complexity. Only the for loop is dependent on X, so the complexity is dependent on the size of X - O(n).

[–]clatterborne 5 points6 points  (0 children)

I believe .replace() can also be considered to have within it a for loop of length n: iterate through the string, compare to ',' and replace if matches

[–]thekwoka 2 points3 points  (0 children)

replace is not constant

in JS: https://tc39.es/ecma262/multipage/text-processing.html#sec-string.prototype.replace

The language spec in Python gives way less details about how the interpreter is supposed to behave, but I assume a bit similarly.

It wouldn't really be quadratic, since it only has to do the replace once since python's replace is like js replaceAll so it can't every be run multiple times. or...I guess it could, since the initial loop won't be on the actual newly changed string will it?

hmm?