r/ProgrammerHumor • • 1d ago

Meme dontYouDareToDeceive

Post image
907 Upvotes

40 comments sorted by

270

u/IHeartBadCode 1d ago

Before you know it, they'll have O(1) time method for factoring all even primes.

86

u/dangderr 1d ago

We’ve actually been able to factor all primes in O(1) for a while now.

21

u/Murphy_Slaw_ 1d ago

Erm, actually it can't get under O(n) because just outputting n is O(n).

30

u/prumf 1d ago

What no you changed n from the number to its size.

Printing n is O(log(n))

5

u/soussang 1d ago

Ahem. Yes, it's true for integers which prints in O(log_b(n)).

But have you consider printing those in binary? O(1) for all fixed sized integer types (__int128 go brrrr). Is it slower than the integer printing? Maybe. Does it falls appart if you need more bytes? Maybe. Are you willing to make a template/macro which can unwrap a N sized loop to maintain O(1) for any arbitrary fixed size? I'll let you decide.

3

u/Bartodziejj 1d ago

O(log(n)) is a subset of O(n)

4

u/Vivid_Dot_6405 1d ago

Correct and this is why I dislike the use of Big O in non-academic discourse because when people use Big O they usually really mean Big Theta, which is a tight bound and not an upper bound like Big O.

2

u/dangderr 1d ago

I didn't say anything about outputting?

You must be an amateur haxor if you're outputting all your factored primes in the middle of an attack smh

If you just have to pass back a pointer to the result, it's O(1).

1

u/hary627 1d ago

"are any of these even numbers prime?" Always has the same answer

6

u/Frodojj 1d ago

Two is prime.

3

u/evorm 1d ago

That's still just 1 iteration.

2 ? yes : no

0

u/48panda 1d ago

Quantum algorithms exist with complexity smaller than its input

15

u/Front_Committee4993 1d ago

print("2,1")

5

u/overclockedslinky 1d ago

SoURcE?!??!

2

u/Neon297 1d ago

print("2")

6

u/BenTheHokie 1d ago

You can factor any integer in O(1) as long as you guess it right on the first try

-1

u/onepiecefreak2 18h ago

That's not how Big O notation works

2

u/Rainb0_0 2h ago

Best case should be O(1) right?

0

u/onepiecefreak2 2h ago

Big O notation represents the worst case runtime. Sorting algorithms also aren't O(1) just because there is a chance that the list is already sorted.

1

u/Unupgradable 16h ago

But it is how smol o notation works... Sort-of

5

u/Willinton06 1d ago

O(0), all primes already exist in the abstract plan of math, good enough for me

2

u/Vivid_Dot_6405 1d ago

Easy.

Suppose there exists a memory storage device with infinite capacity and that the maximum speed of causality can be safely ignored because the device is extremely small. Also suppose that infinite time is available. Now assume all prime numbers have been calculated and stored on the memory storage device. Thus, an algorithm for calculating an n-th prime merely reduces to retrieval of data from the memory storage device, which has time complexity O(1).

44

u/djonoy 1d ago • Bravo

ERROR: expected comparison but found expression instead

62

u/seba07 1d ago

The algorithm "wait a million years; answer 42" is O(1) but wouldn't be usable for anything. P=NP does not mean that there is a way to solve problems in NP fast.

13

u/Ksevio 23h ago

It's been a while since I took algorithms, but I recall you can break down any NP problem to the simplest form and then if you could prove that could be solved in polynomial time, you'd be able to solve NP problems fast

16

u/seba07 23h ago

There is a difference between computation theory and practical implementation. As I was trying to highlight, an polynomial algorithm does not mean that it is is fast. It just meant the complexity doesn't grow that fast.

2

u/TldrDev 10h ago

The implications of P=NP are currently unknown. It could be that all NP problems are NP fast. It could be we have to compute infinitely. It could be just walking a tree to the answer. It depends on if P=NP, and what type of solution we find. You are talking in certain terms, but in my opinion, probably shouldnt be.

2

u/seba07 5h ago

It also depends on the type of proof. Maybe someone shows that P≠NP can't be true (not likely but could be). That would solve the problem but doesn't give an algorithm.

5

u/bender3600 23h ago edited 22h ago

Yeah, but just because its considered asymptotically fast does not necessarily mean it's actually fast to execute.

An example is integer multiplication. The asymptotically fastest known algorithm is O(n log n) but the hidden constant is so big that it only becomes faster for integers with trillions of digits.

And of course a Θ(ngoogol ) algorithm would also be considered fast because it's still polynomial but it would not be practical

1

u/TldrDev 10h ago

This is only one possible outcome.

NP problems are often a family of problems where if you solve one, you solve them all. The same algorithmic solution can be applied across a huge range of disciplines. In the past, we have solved such problems where the solution is literally trivial. For example, computing some digit of pi or checking subsets of prime numbers.

Instead of calculating permutations we are essentially able to walk to the answer directly.

That would make things completely calculatable in essentially arbitrary time frames.

You are assuming its impossible, but id disagree.

Imagine the traveling salesman problem, where we make a tree of all possible states of that problem.

Right now, iterating the permutations and checking each possibility makes it computationally prohibitive & expensive.

However, there might be a solution to the problem such that you can walk down the tree of possibilities directly to the answer. This would be a solution such that P=NP, and you do not need permutation at all.

If you solved that problem, you can apply that same solution to literally tens of thousands of adjacent math and computer science problems.

We do not currently have that solution, and it is unclear if it will be something as easy as walking the tree, or using permutations which are incalculable.

The implications of this question remains to be seen. We will know if we ever get an answer.

1

u/bender3600 2h ago

I'm not assuming anything. I simply stated that just because something can be solved in polynomial time it doesn't necessarily mean that it's practical to solve, not that it can't be.

28

u/Front_Committee4993 1d ago

Let N=1

11

u/differentiallity 1d ago

Or P=0. See? Not so easy.

11

u/Alzusand 1d ago

Please let it be true it would be so funny.

0

u/Jersey_2019 1d ago

Then Quantum computing field would go away in an instant 😭

3

u/Substantial_Top5312 1d ago

n=1 or p = 0

1

u/Wiseon321 8h ago

I refuse to believe this thought experiment is even important.

1

u/Benjam438 7h ago

If P=NP I'm skeptical of the letter N

1

u/AkrinorNoname 1h ago

P=NP only for N=1 or P=0. No idea why everyone is so worked up about this.

0

u/username_6916 1d ago

Show all your work for full credit.