>Number of times I have had to invert a binary tree in my 25+ year career: 0. Number of times I have been asked to invert a binary tree in an interview: 0
Well, if you wanted to pull that card, it would have been nice to mention the sorts of problems you've worked on in those 25 years.
>What I would do if I had to invert a binary tree: look it up.
Unless you're already good at algorithms, it would net you a mediocre solution.
For e.g. You would only know that there are multiple ways to implement an algorithm when you've actually done the work dozens of times and noticed that some implementations won't be appropriate for you needs. Like with many things, its about having experience, knowing whats a good fit, and knowing why something similar isn't a good fit.
Certainly - every single time you choose an algorithm, and then decide on a particular way to implement it - you could in theory, implement each algorithm in 10 different ways and then choose the best one after benchmarking. But that would be a huge drag on productivity. And if you had to choose 5 algorithms for 5 different tasks then it quickly becomes a quadratic complexity time sink. It would be far better to just know via experience. Its kind of like in chess - the better players just KNOW that certain paths lead to less favourable winning odds. Well, novices do take those paths and eventually find out the hard way !
>> Well, if you wanted to pull that card, it would have been nice to mention the sorts of problems you've worked on in those 25 years.
Quite a range of stuff, unsurprisingly. I started on an HP3000 mainframe in 1976, if you want to go back to the very beginning, writing BASIC programs on a teletype or one of the two early CRTs, and storing my programs on paper tape.
Since then I've worked in DOS, 16-bit Windows, 32-bit Windows, 64-bit Windows, Ubuntu, iOS, and Android, using Pascal, 8086 assembler, C, C++, C#, javascript, Python, and Java. I've worked on applications in multimedia, telephony, banking, insurance, pharmaceuticals, cosmetics, health care, and I'm sure a few other things I've forgotten.
All of which will mean jack squat if, tomorrow morning, the most important thing I have to do is invert a binary tree. But I'm fairly certain I would be able to figure out what I needed to do, and I am fairly certain I could manage to implement it well. It's what we're supposed to be able to do, and if you think that having studied up on it so that you could pass a Google interview means that, a few years down the road when you actually need it you'll just whip it off the top of your head, then I think life may hold some surprises for you.
Thanks for replying. I simply wanted to know what kinds of problems you worked on. A binary tree can be inverted presumably on any OS and using most languages. If you're going to claim that a basic binary tree operation has not be necessary for you in your 25+ year career, you should have mentioned your problem (!industry) domains. It was nothing personal.
>and if you think that having studied up on it so that you could pass a Google interview means that, a few years down the road when you actually need it you'll just whip it off the top of your head, then I think life may hold some surprises for you.
That is a misrepresentation of what I said. I said that _RETAINING_ basic and higher order CS fundamental knowledge is much more useful, in a way that simply looking up an algorithm on wikipedia would not be.
>> That is a misrepresentation of what I said. I said that _RETAINING_ basic and higher order CS fundamental knowledge is much more useful, in a way that simply looking up an algorithm on wikipedia would not be.
Sorry it was not my intention to misrepresent you. I was assuming that we all agree that simply looking something up without having any fundamental basis for understanding would not be of much use, and that we further assume the person doing the searching is in need of a refresh, and not basic education in the craft. In that context it is the idea that you might be called on to go up to a whiteboard and trot out something you haven't done in three years, and then be judged competent or not based on how successful the trotting is, that gets people worked up.
I totally agree with you. Even if a binary tree is considered a fundamental data structure I think CS is a large ass domain and you can go for years programming, designing data structures and working with algorithms without the need to reimplement basic operations on binary trees.
Well, if you wanted to pull that card, it would have been nice to mention the sorts of problems you've worked on in those 25 years.
>What I would do if I had to invert a binary tree: look it up.
Unless you're already good at algorithms, it would net you a mediocre solution.
For e.g. You would only know that there are multiple ways to implement an algorithm when you've actually done the work dozens of times and noticed that some implementations won't be appropriate for you needs. Like with many things, its about having experience, knowing whats a good fit, and knowing why something similar isn't a good fit.
Certainly - every single time you choose an algorithm, and then decide on a particular way to implement it - you could in theory, implement each algorithm in 10 different ways and then choose the best one after benchmarking. But that would be a huge drag on productivity. And if you had to choose 5 algorithms for 5 different tasks then it quickly becomes a quadratic complexity time sink. It would be far better to just know via experience. Its kind of like in chess - the better players just KNOW that certain paths lead to less favourable winning odds. Well, novices do take those paths and eventually find out the hard way !