r/badcode • • 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

Post image
1.2k Upvotes

80 comments sorted by

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

0

u/[deleted] Jul 30 '21

[deleted] — view deleted 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))/2 from 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

0

u/[deleted] Jul 30 '21

[deleted] — view deleted comment

0

u/WinstonCaeser Jul 30 '21 edited Jul 30 '21

When you don't understand complexity theory enough to know that Big Omega is a lower bound, where Big O is an upper bound, therefore anything's Big O is at least its Big Omega... Oof.