Live data from Hacker News

Algorithms Interviews: Theory vs. Practice (2020)

danluu.com

41–50 of 69 posts

Re: Algorithms Interviews: Theory vs. Practice (2020)

#41
post #10

Earlier quoted context omitted.

Annoying counterpoint, of course, I've seen senior developers also stall out on avoiding quadratic code to the point that they didn't get the code delivered and then the project got scrapped. The most widespread failure I have seen, by far, is to write code that is so abstracted out that it isn't really clear on how to get the necessary parts inline to get at efficient code. You'll have an obvious path on how to load…

Echoing my sibling commenters here, I’d love to hear more about this situation. Usually “inlining” and algorithmic complexity are juxtaposed as orthogonal types of optimization, with algorithmic optimization typically even being the reasoning for why the level of abstraction doesn’t matter very much. You typically get a much better speed up from going from O(n^2) to O(n) algorithms than from implementing e.g. Duff’s…

My apologies, forgot I posted.

On phone, so will be brief. Will try a longer response later. (Apologies to other responses, not hitting them all.)

Basic point is that many will abstract out data to different locations and ownership lifetimes. So, congrats, you kept us at a lower complexity, but failed to realize you need to first essentially reindex all of the data for that to happen.

Now, I grant that often the problem is more in the data scattered over any number of databases. If there are reasons to keep that spread, though, hard to just sweep it aside.

And then there are those that don't accept, "send it to a solver." Really annoying how often people assume they can easily beat cplex and friends.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#42

Earlier quoted context omitted.

>their weak solution can easily cost the company and its other engineers far more than it would have cost to interview engineers properly and compensate the fewer qualified engineers commensurately. Anything that supports this? Because I don't believe it at all The only thing that I can think of that could cost company a lot is data corruption / database being destroyed Unless it is very specific case like HFT

That is pretty much my stance, too. I've seen a lot of critical fuckups in my years, but I have yet to see someone fuck up everything by using a woefully unsuitable algorithm. That, of course, does not mean that it doesn't happen - could very well be the case at the type of companies I haven't worked for, where performance is absolutely critical...but I have a hard time believing those places don't have safety guards…

I agree at the level of source code, but sometimes algorithm skills affect the whole architecture. Even simple things like where certain data and logic would optimally exist can have cascading and compounding consequences for the whole rest of the system. To see better solutions, you have to know what's possible with algorithms and data structures.

To give a contrived example that I think should make sense no matter what kind of software people actually work on:

Imagine nobody had ever figured out video compression and the only way we could see electronic video required orders of magnitude higher costs. VOD and video conferencing may not even be viable for most people. We'd still be live streaming television over analog radio. It would have vast consequences throughout other technologies and what we can do with them.

If a service gets the kind of viral growth that their creators dearly hope they will, that will almost certainly involve a level of scale that would benefit from knowledge of algorithms (including practical mathematics as a subset) and the difference between a good or bad solution could have far-reaching consequences. Of course many problems do have well-known solutions that anybody can look up, but many projects do end up needing solutions novel to them.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#43
post #9

I have definitely seen senior developers put quadratic and even exponential algorithms into production and cause global outages. Code review didn't help, because their code was reviewed by other people who were interviewed to the same low standard. I continue to insist on algorithm & data structure interviews for software engineer candidates. Not every project needs them as much, but in large enough institutions, eve…

> Not every project needs them as much, but in large enough institutions, every engineer is likely to run into at least one project that does. If they can't figure it out and can't get help from someone who can, their weak solution can easily cost the company and its other engineers far more than it would have cost to interview engineers properly and compensate the fewer qualified engineers commensurately.

I worked at a very large company (over 100K employees) for over a decade. I definitely encountered problems where knowing complexity and graph algorithms helped. Not knowing them would have cost the company almost nothing.

I think you're subject to survivorship bias. Many (most?) large Fortune 500 companies make the bulk of their money by simple business logic and grunt work. Not by scaling. Internet based companies (which are the minority) are outliers.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#44
post #9

I have definitely seen senior developers put quadratic and even exponential algorithms into production and cause global outages. Code review didn't help, because their code was reviewed by other people who were interviewed to the same low standard. I continue to insist on algorithm & data structure interviews for software engineer candidates. Not every project needs them as much, but in large enough institutions, eve…

>their weak solution can easily cost the company and its other engineers far more than it would have cost to interview engineers properly and compensate the fewer qualified engineers commensurately. Anything that supports this? Because I don't believe it at all The only thing that I can think of that could cost company a lot is data corruption / database being destroyed Unless it is very specific case like HFT

Agree with you. And for specific cases like HFT, the interviews will be a lot more specific in that area anyway, so it would be weird for a "senior developer who doesn't know algorithms" to pass in the first place.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#45
post #19

If you don’t know Dan or haven’t read enough of his work to get this, > I can't pass algorithms interviews! When I say that, people often think I mean that I fail half my interviews or something. It's more than half. is insane. Dan’s day job is (or was, on the occasions that I’ve worked with him) to identify and solve the weirdest, gnarliest scaling and performance bugs in extremely large systems. If Dan isn’t passin…

> If Dan isn’t passing your algorithms interview, it’s not testing what you think it is.

I think it's also much easier to see/solve problems in practice than on a theoretical whiteboard.

I've rarely had to use Leetcode level algorithms at work. But when I did, it was much easier to solve than if I'd been given the exact same problem without the context of the experience I'd accumulated working on the project.

Example: I wrote a C++ program that stored a large number of 32 bit numbers[1] in a map (both key and value were 32 bits). When I ran the program, it ran out of memory (something like 80GB of RAM). I quickly realized that the map had a high overhead - all those pointers in a red-black tree consume more RAM than my data! As I was storing only once and doing lookups many times, it was simpler to simply sort all the keys, and then store the values. When I needed to do a lookup, I'd do a binary search and find it. Algorithmically same complexity as a map.

If someone gave me this problem as a whiteboard, I'd implement the map based solution, and would really struggle if I started getting questions about memory performance, and it would be silly to ding me for not choosing a binary search. In reality, my screwup was extremely simple to solve - given that I had a good understanding of the problem domain - something lacking in a whiteboard interview.

So in general, people who do poorly in those whiteboard interviews may well solve the exact same problem with ease in an actual work situation.

Another example: I wrote a DAG and needed to check if two (arbitrary) nodes were connected. I chose a fairly inefficient algorithm - recursive backtracking with no memoization. If I've already computed that B is connected to C, and I know A is connected to B, I don't need to run the whole algorithm to know that A is connected to C.

I wrote the simple, inefficient version, knowing it was a poor algorithm. But my reasoning was that I wanted to write all my tests with corner cases working before I fixed the performance.

Once I had all the tests written, I returned to optimize the algorithm. Then I said "Heck, let's see how bad it is with real world data."

The algorithm was fast. Even when I significantly increased N. How come?

Oh, it's because due to real world limitations in the problem I was solving, the maximum distance between any 2 nodes I was comparing was 7. Yes, in the abstract, it seemed very inefficient, but when you apply real world limitations, you realize there is nothing to gain by making it more efficient. Leetcode biased folks would have made the code more complex for little gain.

[1] Maybe it was 64 bit - I forget.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#46

The goofy thing is that these questions feed back into dev culture and create a perception that people who’ve worked at a FAANG must be a god of programming. Call it what it is: your intellectual laziness in evaluating people and your own bias towards “winners.” Regression to the mean is very real. I doubt an org of sufficient size can truly beat it, if only because not every employee can do well in every situation/p…

It absolutely is intellectual laziness. There is zero attempt by hiring management to improve their own quality.

They use bottom of the barrel practices for hiring (such as leetcode), practices for collaboration (stack ranking), for distribution of rewards (skimping on existing employees in favor of hiring more headcount), and generally incapable of creating and sharing solid visions and giving people the resources to get them to fruition (Sitting back after OKRs are decided out of thin air, never truly explaining why something is important and never really supporting their reports to achieve those goals).

Re: Algorithms Interviews: Theory vs. Practice (2020)

#47

Question based on some surprising-to-me chatter in a thread some weeks back about interviews: When people claim that some shocking proportion of allegedly-accomplished candidates can’t write basic code to perform even a simple task on a whiteboard—do they mean pseudocode, or something akin to that? Or are they counting off points for getting actual syntax wrong? Because I’ve been paid to write code for more than two…

Plenty of candidates can't figure how to use a for-loop to iterate over input or even how to handle nested data (Trees).

If you're biggest worry about leetcode is does this language need a semi-colon at the end then I doubt you have trouble interviewing.

---

Do you do much interviewing as an interviewer?

Re: Algorithms Interviews: Theory vs. Practice (2020)

#48

Question based on some surprising-to-me chatter in a thread some weeks back about interviews: When people claim that some shocking proportion of allegedly-accomplished candidates can’t write basic code to perform even a simple task on a whiteboard—do they mean pseudocode, or something akin to that? Or are they counting off points for getting actual syntax wrong? Because I’ve been paid to write code for more than two…

Plenty of candidates can't figure how to use a for-loop to iterate over input or even how to handle nested data (Trees). If you're biggest worry about leetcode is does this language need a semi-colon at the end then I doubt you have trouble interviewing. --- Do you do much interviewing as an interviewer?

I have in past roles. We never leetcoded anyone where I’ve been an interviewer. One place where I guided it my approach was to attempt to learn something from the candidate—this not-infrequently led to my being the only person (they claimed) to have ever e.g. engaged them in a conversation about a paper they authored and listed on their résumé. Which, wtf, how do you not get curious enough to skim that before the interview and ask a couple non-stupid questions about it?

I don’t exactly have a dataset (who does? A few Bigcos but most interviewers are working with tea-leaves and guesses) but I really liked the “try to learn something” approach and would use it again. It helps that I don’t know much so it’s pretty easy for me to find something I don’t know that the candidate can teach me about, I suppose—maybe this doesn’t work so well for people who know a lot and also aren’t good at faking not-knowing things.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#49
post #5

Meanwhile in real life it's mostly - better error handling (you don't want your batch to fail because 1 of 1 million items had an issue, usually) - sane retry/timeouts - fixing bad db queries

I prefer to ask questions that are easier on the algorithm side and have time to see how well the interviewee covers edge cases, handles errors, shows me that it works, and writes tests. Our company's work is more about reliability than efficiency.

Re: Algorithms Interviews: Theory vs. Practice (2020)

#50
I wrote an HN submission somewhere about the biases I've seen in algo interviews. One thing is they love questions that can be solved with some small twist on BFS or DFS, usually one that's a lot easier if you're doing it non-recursively. I've gone through entire multi-round interviews like that.
Post reply on HN