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 edited Jul 30 '21
For any Turing machine (the theoretical computer) multiplication is at least O(num digits). On any machine to multiply two numbers of unbounded size it takes at least O(num digits).
You need to brush up on your complexity theory if you are going to try and be pedantic.
You make keep making the same assumption about the architecture, that numbers are upper bounded. This is in many cases an invalid assumption and must be explicitly stated.
How can it not affect the algorithmic time complexity? Whether the assumption about upper limits is made changes
(n *( n+1))/2from O(1) to at least O(n). Where n is the number of digits.Edit: Once again linking Wikipedia in hopes that you'll read it and stop embarrassing yourself.
Relevant quote: "There is a trivial lower bound of Ω(n) for multiplying two n-bit numbers on a single processor; no matching algorithm (on conventional machines, that is on Turing equivalent machines) nor any sharper lower bound is known."
https://en.m.wikipedia.org/wiki/Multiplication_algorithm#Lower_bounds