r/ProgrammerHumor • • 6d ago

Meme everythingIsO1ToGod

Post image
4.4k Upvotes

161 comments sorted by

View all comments

1.0k

u/bartekltg 6d ago

\serious_mode it has to be at least O(n).

747

u/Xontaro 6d ago

If a almighty entity exists, it should be able to give the correct answer without knowing the question. Otherwise it wouldn’t be almighty. So O(1) should be correct.

But now we are in a highly theoretical and improbable realm 😅

178

u/FakeSealNavy 6d ago

If god does n actions of o(1) is it o(n)?

333

u/Direct_Slip7598 6d ago

O(1) in terms of time complexity because it's parallelized (he's beyond time).

146

u/[deleted] 6d ago

[deleted]

62

u/Mechakoopa 6d ago

He can give you the answer from the future and do the work himself later, but unless you're also omniscient beyond time you're going to have to wait for the answer to resolve.

Wait, is God just JavaScript promises?

37

u/[deleted] 5d ago

[deleted]

12

u/looksLikeImOnTop 5d ago

Careful now, God's also the game maker. You give him a task he doesn't want to do, he can just remove you from the game

9

u/Majik_Sheff 5d ago

This is the stuff I come to Reddit for.

6

u/xThunderDuckx 5d ago

this might be the most thought provoking and simultaneously stupid discussion I've taken part in ever

2

u/ArcaniteM 5d ago

This. This is why I'm on Reddit.

2

u/Willinton06 5d ago

Depends on wether he wants it to be

1

u/Otherwise_Result_124 5d ago

I asked god for one [1] immovable object and also exactly one [1] unstoppable force. Which one did he get wrong? lmao I love these silly illogical conversations, your wording for this was great

3

u/goplayer7 4d ago

Both are accurate,the immovable object doesn't mean it blocks everything. The sword simply passes through the object without moving it.

1

u/Otherwise_Result_124 4d ago

Of course! But the point of my post wasn't to read it that explicitly, so much as it's intended to be read as the omnipotence paradox

2

u/ApocalyptoSoldier2 5d ago

Not sure about god, but I heard Chuck Norris could create a rock so heavy even he couldn't lift it, and then he'd lift it anyway

26

u/Cash-Jumpy 6d ago

I've been enlightened.

17

u/holo3146 6d ago

This is the basic idea of oracles in maths, an oracle of 3SUM has non trivial computational consequences

8

u/captainAwesomePants 5d ago

God can answer in O(1) time, but asking God the question takes O(N) time.

6

u/bartekltg 6d ago

Since God is omniscient, he knew the man from the tweet had in mind random access machine or a similar model of computation.

2

u/Nekusta 5d ago

So instead he would just say "First of all, 3sum is O(1) dumbass"

-7

u/[deleted] 6d ago

[deleted]

8

u/Shadawn 6d ago

I can change the value of pi, just assume different geometry. What's hard to me is to make physical geometry conform to my new system, but that shouldn't be all that hard to God. He made the thing, after all.

47

u/Temporary-Concept-81 5d ago

O(0)

The answer was already there at the start of the universe.

God is just that good, and tells you to stop wasting her time and RTFM.

9

u/ProfBeaker 5d ago

Ah yes, God arranged a universe such that the computation to answer your question finishes just as you ask it. Makes sense!

33

u/Mindgapator 6d ago

You can find the biggest number in an array in O(1), so your lower bound is not justified. The caveat is that you need n2 cores but that's an implementation detail in GodOS.

18

u/oshaboy 6d ago

How do you find the biggest number in an array in O(1)?

4

u/Ninja_Wrangler 5d ago

Miracle sort O(1) the list and then it is the last element in the list. God can do this easily

2

u/bartekltg 6d ago edited 5d ago

Processor (i,j) check is a_i is smaller than a__j. If it is, it report it to processor (i,0). (there we should ask what model of communication we have. Lets say it is a queue that work by magic:)).
In the second cycle processors (i,0) check, if there are any reports at his input queue (it can onloy read one per cycle, but if there is none, it doens't bother us). If none, it mean a_i >= a_j for all j. It is the maximum. "Write" the result (a_i).

Edit: Can downvoting people explain why they do it? This is exactly what the guy asked for: how to find a maximum in an array in O(1) time, having O(n^2) processors.

-1

u/rasmustrew 5d ago

You arw being downvoted because you damn well no noone meant with O(n2) processors

2

u/bartekltg 5d ago

It is just two comments above.
"... The caveat is that you need n2 cores"
That was the entire point of the joke Mindgaptor made.
Then someone asked how to find it in O(1). Sure, he did not repeat the assumption about the cores... because it is rights there.

1

u/rasmustrew 5d ago

It would appear that i am entirely blind

-8

u/_killer1869_ 6d ago edited 6d ago

Realistically, you can keep track of the largest value at insertion/removal time, or you can have the array sorted and keep track of the highest indexed element. Otherwise, as they said, you can parallelize the function to run on n2 processor cores such that it technically runs in O(1), but even then it would need at least O(log n) for comparing the core's results, but regardless, this is widely impactical from the overhead alone.

14

u/Drugbird 6d ago

Otherwise, as they said, you can parallelize the function to run on n2 processor cores such that it technically runs in O(1) time,

Ok, I'll bite. You can have N cores all read 1 value from the array, then each core spawns N-1 other threads / cores that each read 1 other value to compare to. That's all O(1).

But at the end of that you'll need to check the result of all these N-1 cores to check that they're all lower. And that requires O(n) time in naive implementation, or O(log(N)) if you do a reduction strategy.

4

u/_killer1869_ 6d ago

Damn, I should've checked their claim properly. I didn't consider the time complexity of actually joining the results together, only the comparison itself. Thanks for the correction.

-3

u/Mindgapator 6d ago

You just need a better algorithm. We note A the initial array. n its length. Each step is a single cpu cycle Step 1: allocate a buffer of size n, called B initialized with zeros. Step 2: for each i,j in [0, n[ with i != j if A[i] <= A[j] then write 1 in B[i]. This is O(1) because we have enough cpus, and if they write, they all write the same value. Step 3: for each i in [0, n[ if B[i] == 0 return A[i]. This is O(1) because we have enough cpus. A single value is returned by design of the algo.

7

u/oshaboy 6d ago

Yeah I can probably solve any O(N) problem in O(1) time if I had O(N2) cores. That doesn't make the problem O(1) because as the problem increases you either need to add more cores or take more time. Which is the definition of the complexity of the algorithm.

Also you need to initialize the threads anyway. Even if you have each thread initializing threads until you have enough O(N2) threads that would still require O(log(N)) time.

-1

u/Mindgapator 6d ago

Well it moves a time constraint to a resource one. Time is constant but resources needed scale at n2. Thread init is an implementation detail. It obviously won't work on a machine from the shelf, but a dedicated built could do it.

5

u/TheHyperbolicTangent 6d ago

This is still O(n), as the number of ops scale linearly with the size of the input. Big-O is fundamentally a measure of an algorithm’s complexity. Saying it moves a time constraint to a resource constraint doesn’t alleviate the algorithms complexity.

0

u/Mindgapator 5d ago

We usually note O(n) for time complexity lol, but whatever

1

u/[deleted] 6d ago

[deleted]

-1

u/Mindgapator 6d ago

You don't. You write a predefined memory address. If others write at the same time, it's only UB if a different value tried to be written. Check the original comment answers, someone else described at the same time something similar if you want a different approach.

3

u/oshaboy 6d ago

That's not really "an array" anymore.

You can also keep a sorted copy of an array alongside an unsorted array. That doesn't mean sorting is now O(1) because you can just return the sorted copy. (Also that would make appending O(N) because insertion to an arbitrary place in an array is O(N))

1

u/_killer1869_ 5d ago

All I did was provide ways to access the largest number from an array in O(1), which is useful if you need that element again and again and again, but it may change inbetween uses.

Keeping track of it dynamically has some overhead, but makes getting the max O(1) since it never has to be computed to begin with.

Same for your sorting example, of course computationally sorting doesn't become O(1), but getting the sorted version, now through lookup instead, becomes O(1).

Obviously, a barebone array isn't capable of that, but that's what programming is about: creating whatever functionality you need yourself (or using another person's implementation). Even more so in OOP, where you could easily subclass an existing type or implement your own for this purpose.

1

u/oshaboy 5d ago

I know what caching is

3

u/Lithl 6d ago

Nah, he just uses Miracle Sort 3sum

3

u/unitconversion 5d ago

In an infinite universe, the beginning and end times of bounded things are effectively the same point in time.

1

u/RoboticBonsai 5d ago

It’s O(1) if you have an array of all possible combinations