Sleeping through the technical interview (2022)
xeiaso.net
xeiaso.net
> In computational complexity theory, a numeric algorithm runs in pseudo-polynomial time if its running time is a polynomial in the numeric value of the input (the largest integer present in the input)—but not necessarily in the length of the input (the number of bits required to represent it), which is the case for polynomial time algorithms.
You understand that this is part of the joke, right?
If we really want to get down to the details and kill the joke, then you don't actually need to wait real time. Computational complexity is concerned with steps in a computational model, not how much time passes on a clock. Sleep sort uses OS scheduler properties and in a virtual time environment, time advances to the next scheduled event. That's what brings you back to actual polynomial complexity, if you assume this kind of thing as your computational model.
> - it's psuedo-polynomial.
If you lecture people then please at least get your spelling right.
Haskell's runtime and the OS it executes on exist only as a transient implementation detail of what is, literally, a pure environment!
I fail to see the joke, really. I only see false and nonsense statements, which still could be funny or interesting, but I don't see how?
On the joke part, sleepsort is intrinsically an extremely funny concept and I think everyone here gets that. But "constant time" has a rigorous/pedantic definition, which sleepsort doesn't meet, so I think for some readers calling it that kills the joke (in the same sort of way that it would kill the joke if TFA's code snippets used lots of invalid syntax).
I like the idea of (ab)using the scheduler to sort numbers.
Now I'm inspired to make my own "sorting" routine, maybe touching filenames and then sorting them with `ls -n`, or rendering triangles and then ripping them off in z-plane order, or stuffing frames into a video and then playing it back.
(I said integers but I don't think that's significant, just a matter of encoding scheme - we can use a single 0 for decimal point and two for delimiting inputs say.)
But anyway isn't the joke that sleep-time doesn't count, because the computer could be doing something else? It's actually quite compelling in a 'this is stupid, I love it' sort of way.
[0] https://www.cs.princeton.edu/courses/archive/fall13/cos226/l...
[0] - https://aphyr.com/posts/353-rewriting-the-technical-intervie...
https://joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/
To whet your appetite:
> interviewer: Um, you understand the problem is fizzbuzz, right?
> me: Do I ever. So, now let's talk models. I'm thinking a simple multi-layer-perceptron with one hidden layer.
But there is an (almost) truly constant time sort, using an abacus instead of a computer: https://en.wikipedia.org/wiki/Bead_sort
Creating ‘N’ threads and adding them all to a sorted wake list will be between O(N log N) and O(N^2), depending on the OS and/or language runtime.
There is either a sorted list, a heap, or an N^2 algorithm somewhere behind the scenes.
Similarly, the sleep sort itself is at least linear time. You have to wake N threads to output N sorted items.
Worse, in wall clock time it also scales with the values. You could compress the range by first finding the minimum and maximum values, but that’s also … linear time.
https://en.wikipedia.org/wiki/Ultimate_fate_of_the_universe#...
In practice, of course, no system actually does this. Syscall timeouts just aren't a place where this is typically beneficial. Also, naturally, it would be better to just directly apply a radix-sort which only scales with log(max_value) rather than linearly with max_value.
This is not a fundamental limitation of scheduling systems, especially if you take into account the possibility of special hardware allowing for constant-time-with-respect-to-number-of-threads scheduling. For example, it is trivial, though economically infeasible for any practical purpose, to construct a scheduler that performs scheduling by bouncing infopackets via laser beams off of a gargantuan set of mirrors of varying distances back onto a detector connected to the computer, relying on the speed of light to perform a delay of the specified duration. This shows that sleep sort does not inherently rely on the hidden algorithmic complexity of whatever thread scheduling approach is used, since that can be optimized to O(1) in theory, if not in practice.
It's a subtle metalinguistic joke. It's supposed to poke fun at understandings of how computer science works by turning them on their head.
I'm sorry the joke didn't land on you.
Maybe it works as a sort of dadaistic literature, like the ones where they redefine "chair" to mean "table" and so on, but beyond that?
Both your article and this comment of yours show that you're annoyed at algorithmic interview questions, so you're trying (well, at least in this fantasy) to one-up your interviewers by being smarter, and technically correct, but in an unexpected way. I understand the sentiment, but unfortunately, this only works when you're actually at least technically correct.
I'm working on more stories in this "universe" but it takes a while for the satire juice to build up. Maybe the next one will be on spatial computing.
Sounds like our universe . . .
I think that universe is better at naming things.
> In a flash, one line of code is changed:
-forM_ values (\time -> forkIO $ threadDelay (100000 * time) >> writeChan chan time)
+forM_ values (\time -> forkIO $ threadDelay (10000 * time) >> writeChan chan time)
> "It is now ten times faster."The whole process could take a month, require at least 2 days off and significant amount of travel.
Today? A recruiter/HR person rings you and asks, can we have a video call? You have that 15~20 min call the same day, they submit your CV to whoever makes the decisions, then they schedule one or more video interviews/tech sessions, some companies ask you to do behavioral/skill tests from the comfort of your own home. All of it can be done during a lunch break if you're a remote worker... What's not to like?
Yes, the communication bandwidth face to face is much higher, but only remote allows me to interview for a company in Tel Aviv in the morning, Warsaw midday and a Californian one in the evening all on the same day.
Sorting [5, 50] is faster wall time then [6, 60].
is just as fast as
[9]
If you really want to make it strictly constant time, just append INT32_MAX to the end of the array before sorting, and then pop it after.
A subproblem also considers the elements to be integers, then they become another "value" domain. (But in general, sorting problems only need their elements to be comparable, not necessarily integers.)
Not to mention for the OS to handle N threads would likely take some kind of non-linear time, at least N^2 if I had to take a shot in the dark. But I imagine it'd depend on the OS and how the hardware handles interrupts. Even if the thread is sleeping it still takes resources to schedule it
[1] https://en.wikipedia.org/wiki/Completely_Fair_Scheduler#Algo...
An algorithm that takes N inputs, does N operations, and then sleeps for 10 seconds is not constant time, because in the asymptotic case the N iterations will take longer than the sleep.
- have an upper bound on the input (largest number)
- you must not count some arbitrary things, like reading and processing the input, or spawning threads
But if are allowed to do these things, all the other sorts will became constant time. (I believe only one of them is enough.)For sorting (comparison sorts), one fairly typical model is to just count how many comparisons you do. Which, this does none (kind of, not really, they're really just implicit or hidden in the OS).
It's just playing around with computational models, not a serious proposal. It's either just a joke, a troll, or an parable about the need to be careful about what metric you're measuring. Or some combination of those.
Neither does bucket sort, and nobody has claimed that bucket sort is constant in time.
We only count comparisons in typical sorting algorithms because we know that the overall complexity is proportional to it.
After all, all the sorting work was already done when the threads started sleeping, having registered themselves with the orchestrator (timer wheel etc) that will eventually wake them up. Actually performing the sleep is not necessary.
I don't know about Haskell, but with Rust the tokio runtime lets you do this using start_paused ( https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.ht... )
>After all, all the sorting work was already done when the threads started sleeping, having registered themselves with the orchestrator (timer wheel etc) that will eventually wake them up.
So, modulo several layers of abstraction and a bunch of implementation details I'm glossing over, using a scheduler like this to sort values is just a heapsort :)
please let me know if you have any suggestions thet might fit in, and I'd be glad to even include less mystical folklore like the story of mel but clearly have a theme goin here
1: https://www.illucid.net/posts/homages-to-aphyrs-technical-in...
My criterea don't involve judgement calls :p
The tough choice was to exclude projects without prose; I myself am more comfortable writing code. My own contribution is still down the road, and I bear a great respect for those who have put their words (and themselves) into the world.
In the end, this is basically just bucket sort, only that the buckets are managed by the OS. And nobody has ever claimed that bucket sort is constant time.
I actually got away with using SleepSort in an interview for my current job. It got me the job.
And correctness is the single most important part of an algorithm. We can do any problem in constant time if we don't mind our answers are not correct.
> Against all odds, they wanted to hire you. For a significant amount of money
A small company not trying to cheapskate? Literally unreadable.
If you pick a small unit of time you can make it faster but if the values are sparsely distributed it gets slower.
Okay, if the interviewer had properly done 5 minutes of research on this candidate, they would know know that the candidate is "way over their pay grade". I found all that dance that the article author did a little bit... unnecessary? Kind of how killer whales play with their prey before the kill. Overkill.
Sorry, my answer probably isn't productive, I am merely sharing how I felt after reading it.
I am now off to educate myself on SleepSort :-)
Archive (slightly NSFW text) https://archive.tinychan.net/read/prog/1295544154
People have no idea how many candidates try to apply to backend dev job in an investment bank for 100k a year in China with NO experience in banking, computer science or life in general. Between the guys telling you their dream job is to do nothing and be paid for it, and the dude looking beyond his screen at his friend filling the exercise for him, I've seen it all.
Jeff started again to speak, maybe he actually read your resume. That would be a first. "So it says here that uhhhh-".
Alas, he did not. You wonder why you make that thing if nobody is going to actually read it. You even spent the extra time putting it into normal human language too. The travesty of recruiting continues.
Or something like that. There is so much about the job seeking process that is just stupid and frankly funny.
I'm considering giving Palima an intern in the next article, just because that would be hilarious to me.
The rest of the short story also reads like it came straight from r9k