As stated here it is quadratic, but why?
Asked
Active
Viewed 110 times
-2
-
Oops, you are right :-( Should I delete this? – AmirHossein Jan 24 '16 at 05:54
-
I don't think you can delete questions with an accepted answer. – Paul R Jan 24 '16 at 09:15
1 Answers
5
I think the quadratic part is reading the integer from text. The standard algorithm looks like this:
v = 0
for each digit:
v = v * 10 + digit
It looks like this is just O(n) on the number of digits, but if you are working with arbitrary precision integers like this problem then the multiplication by 10 is also O(n), making the whole thing O(n^2).

Paul Johnson
- 17,438
- 3
- 42
- 59