by tptacek · 11y ago · 0 comments
You're a 55-year old engineer who graduated from school in '81. You're being interviewed by a 24-year old engineer who graduated 2 years ago. You're asked, in an "algorithm interview", to explain some detail of the implementation of an AVL tree.
In reality, despite the fact that they're covered in CS courses, virtually nobody uses AVL trees in industry. In fact, people barely use balanced binary trees at all, and when they do, they use red-black trees, and they use someone else's implementation, because they're a bear to debug.
The 24-year old has an advantage with this question because they were recently taught about, and perhaps had to do exercises/homework/tests based on, AVL trees.
That this happens is stupid, because it's very unlikely that conversance with AVL trees is going to make much of a difference to your on-the-job performance. Almost all the narratives you can come up with about this involve reading tea leaves and are shot down easily by better selection/hiring/interviewing techniques that answer questions more directly.
This line of questioning can go too far; I don't, for instance, think knowing the big-O characteristics of an AVL tree is unreasonable (it's a balanced binary tree, and you should have the complexity of operations on those in resident set throughout your career).
(AVL trees are just the first example of algorithmic trivia that came into my head. Substitute Kruskal's Algorithm, or k-means clustering, or whatever,)
You won't get the job, but that's the correct answer nonetheless. :-)
Interviews suck and we should all stop doing them as much as we possibly can. There are much better ways to handle this problem.
* Tell me more about the problem are you trying to solve.
* There are well tested and tuned libraries for search trees, like the JVM TreeMap. What requirement prevents us from using it?
* The JVM TreeMap uses RedBlack trees, which are basically BTrees, and likely easier / faster to implement than AVL.
Now, you might not get the job because the dude might feel threatened. You just dodged a bullet, the job would have been shitty anyway.
"Why do you want to do that" might be appropriate when actually working, but not in an interview.
I'm not looking for personality, self-confidence or slickness. I just want a person to directly answer the question.
The irony was, I'd just spent the preceding 2 years writing multicast link-state routing code. I could have coded a decent C++ Bellman-Ford in a couple hours, but couldn't pull it out of my head on the spot in an interview without babbling. (I tried to dodge by describing link-state LSP forwarding and then Djikstra, but wasn't given credit for knowing the more sophisticated algorithm).
Algorithm interviews suck. We should stop doing them entirely.
Exceptions are things like you have to iterate through elements in some order, a very high ratio of inserts/deletes to queries, etc -- the obvious stuff.
Much more importantly, vectors are almost always the wrong answer (with a handful of exceptions). Consider a perfectly balanced tree with even 1k elements -- it will have height log2(1k) ~ 10, so approximately 11 reads, almost certainly from main memory, to access an element.
Exceptions are things like you have to iterate through elements in some order, a very high ratio of inserts/deletes to queries, etc -- the obvious stuff.
This is the worst argument ever. You basically said, "trees are the wrong answer, except for when you want to do tree stuff." Want to have a priority queue? Or want to search through your collection without sorting it first? Or insert into your sorted collection? Trees are your friend. They're a tool, just like hashmaps.And no, that's not what I wrote. Trees are an associative data structure. Hashmaps are a better associative data structure, except when you need the few capabilities trees have that hashmaps don't.
ps -- if you run that quote through fold -s -w 77, it won't be so wide...
My apologies. But, I maintain that trees have their uses. I would never use a hashmap to implement a priority queue, and i'd never use a tree to implement associative arrays!
I had an programmer that didn't know that. I went to the whiteboard, explained it, and now she is perfectly competent at it (and the rest of her job). What's the problem?
Where do we get the idea that if someone doesn't know some arbitrary fact that they are incapable of learning it? Hire people that are smart, have good work ethics, and play nicely with others, and everything else will take care of itself.
Having built technical teams numbering in the dozens this is literally the ONLY strategy that delivers long term success in my experience. Unfortunately experience is discounted nowadays...
O(1) is a leaky abstraction [1]. It's O(1) amortized assuming you have enough buckets and a good hashing algorithm that minimizes collisions. I think that distinction important to keep in your head, and good to mention/look for in interviews, since those details matter when things go awry.
[1] http://www.joelonsoftware.com/articles/LeakyAbstractions.htm...
This is why I believe that you, the interviewer, cannot interview someone above your "experience level" without some kind of objective test.
"Work sample test" is the traditional name for what you describe.
[1] edit: that is to say, it has a factual answer if you ask the question and then fall totally silent. Which would be evil, of course, so in practice you and the candidate will naturally turn this question into a back-and-forth repartee, and it will reduce to the same exercise of unconscious biases as the vague question is.