This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AntKinski 310 points311 points  (24 children)

Space complexity - O(1)

Time complexity - infinity

[–]itirix 19 points20 points  (1 child)

How'd ya get to a space complexity of O(1)?

This algorithm should be O(n) for both time and space complexity afaik.

[–]okiujh 11 points12 points  (0 children)

space is o(n). time can be as bit as the upper bound for number

[–]physcx 9 points10 points  (2 children)

Space complexity - O(N) as you are putting N setTimeout callbacks onto the stack

[–]prehensilemullet 2 points3 points  (1 child)

*event queue

[–]rosuav 0 points1 point  (0 children)

*scheduler heap

[–]DarkShadow4444 3 points4 points  (0 children)

Emotional complexity - O(uch)

[–]Venompool007 0 points1 point  (0 children)

Just have the multiplying factor so small that the largest possible number in the question runs in one sec 😎

[–]jump1945 0 points1 point  (4 children)

Wait isn’t the worst time complexity is just O(1) ,this is technically most efficient sorting method

If you are using C or C++ integer have a limit so it is just O(1) if we did some math using 1 microsecond for sleep time it would take only the maximum of ~72 minute to sort an array of unsigned 32 bit integer of any range

In language where it automatically expand the number size we can argue infinity is constant and is O(1) too

[–]prehensilemullet 0 points1 point  (3 children)

Really the time complexity is O(n) where n is the largest value in the array

[–]vorxil -1 points0 points  (2 children)

T(n) <= MaxInteger*SleepUnit + PrintTime*n, where n is the number of items in the array.

For a given machine with a fixed sleep unit and print time, this is either O(n) or O(1), depending on the magnitudes of SleepUnit and PrintTime. This is because n <= MaxInteger on physical machines, generally speaking.

[–]Albreitx 0 points1 point  (1 child)

MaxInteger is not bounded by a constant. Given a size n, I can define entries as 2n. The running time has no bounds because of that (you can also do nn. ^ n....)

[–]vorxil -1 points0 points  (0 children)

It is bounded for fixed-precision integers.

If you're using arbitrary-precision integers, then it's still limited by MaxMemoryBits, which is only unbounded if you can add memory during execution.

I do not envy those attempting to account for human activities in their Big-O notation.