r/badcode • u/zshadowjon • Jul 29 '21
python Was doing some bug hunting and found essentially what was a sum to n function but of O(fuck) time complexity
1.2k
Upvotes
r/badcode • u/zshadowjon • Jul 29 '21
View all comments
Show parent comment
0
u/WinstonCaeser Jul 30 '21
I'm not assuming any underlying implementation, you are.
You are assuming that numbers are capped at some value roughly 264, which is very much an assumption. Because this is in python that assumption is particularly wrong since it has no such limitation.
It is simply a question of what you define as the base "unit", is it a digit, or is it a entire number. You are assuming that the base is a whole number, where I am pointing out that it could also be a digit. It has nothing to do with how it is implemented.
Regardless of implementation any general case multiplication is at least O(num digits).
https://en.m.wikipedia.org/wiki/Multiplication_algorithm#Lower_bounds