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
1
u/WinstonCaeser Jul 30 '21
"There is nothing intrinsically linear about the runtime complexity of the mathematical calculation x * (x + 1) / 2 . You have one input, no recursion, no looping, nothing. It operates in O(1). Theoretically speaking, of course."
There is, intrinsically, you must read every digit making it at least O(num digits).