For example, take red-black trees. How do they work? Most of the time, I shouldn’t have to care. If you need one, every language has an excellent pre-written, well tested, high performance library that you can just use. The important skill is not being able to recreate this library, but knowing how to spot when you can use it profitably to solve a bigger problem, whether it is the right tool, how this will fit into the time or space complexity of your overall solution, etc
And that is exactly why I never ask anyone to implement basic data structures in interviews. Nor would I want to work with anyone who does (unless the work was designing language features).
I used to think this way, but learning data structures isn't just so you know how to implement them. It's about learning what problems they solve and how they solve them, which could inspire ideas on how to solve completely different problems you could face.
A very basic example is a hashmap. I mean you could just tell someone hashmaps are O(1) lookup on average, but knowing how they're implemented along with the tradeoffs of the different implementations could give you ideas on how to partition data on different machines using hashes for example.
Another reason you would want to implement your own is that you don't necessarily want to pull in a massive dependency for a single data structure. It could be useful to implement your own to avoid that hassle(of course risks should be analyzed to figure out whether this is the best course of action beforehand).
Testing people in interviews on these things, maybe not, but they are extremely useful to know, and really are worth learning even if you never really have to implement them yourself.
Please read what I (and Goetz) said again. I absolutely believe that you should know how data structures are implemented, what the tradeoffs are between them, etc. But there's a big difference between knowing how a hashmap works versus having 30 minutes to implement one from scratch. I would much rather focus my interviewing time on more relevant questions.
Goetz is not talking about interviewing, he's talking about software architecture. He's saying that I shouldn't have to care is how a data structure is implemented, I can always rely on some library to do it for me, which is not true. Libraries may not have the API's that you need(in my experience it's the case for graphs for example), and as I mentioned even if they do it may not always be the best idea to use one.
You said that you agree with this, which is why you don't ask these questions in interviews. I said I agree that it might not be the best idea in interview situations, but I just disagree with what Goetz is saying, especially with Java which is very limited in the types of abstractions that can be expressed.
26
u/Roachmeister Jan 24 '21
And that is exactly why I never ask anyone to implement basic data structures in interviews. Nor would I want to work with anyone who does (unless the work was designing language features).