| I had someone in an interview in Berlin ask me to write a garbage collector. In CSC 202, our professor talked about using reference counts. Jeez. I think my profs covered ref counting as an introduction, then also went on to cover mark/sweep and generational collectors. We also covered compaction, copying and bump allocation. I don't think it took that long. If I were running a shop that focused on, say Java, I would want to know if my new hires knew background information relevant to optimizing code running on the JVM. Cycle detection? Man I could probably tell you back when I studied minimum spanning trees and wrote this thing to implement Dijkstra's shortest path: Someone should have given you breadth first search and depth first search, then ran you through how those are components to other algorithms. You should have been left with those as a "toolbox" such that you automatically spend a second thinking, "what would happen to that graph if I did DFS or BFS on it." That kind of toolbox is powerful and gives you all sorts of useful insights. You are not the only one around here to say, "Man I could probably tell you back when..." What you should be thinking now is that you were not well served by some of your teachers. Fortunately, this sort of thing is easily rectifiable. Off the top of my head, I'd hope each node had a unique identifier and I guess I'd mark them/store the keys in a hash table. Well good on you. You just did better than most of my last 6 interviewees. Unless there's a way to mark the data structure, you now have a second structure the size of your key space. This is the DFS/BFS part right here. Is the 2nd part of your statement likely to be true, and how often would it be true? Good call on the marking. (EDIT: Just thought of it: Bloom filter.) I'm sure there are better solutions, but I wouldn't expect a senior program to know them off the top of their head Cripes! Freshmen used to be able to do this stuff! unless you're hiring really specifically for a position writing routing algorithms or looking for a senior airport transit architect. How about you don't want programmers who will end up debugingg an infinite loop induced by a data cycle every single time? EDIT: I actually just wrote cycle detection for my side project in golang the day before yesterday. It took me 4 additional lines of code. If you have a shop that uses gob or some kind of object serialization, this may well be very relevant! |
And either way, if I were to ask this question, I would spend a lot of time helping the person along the way to make sure they were able to make the logical leaps that made sense to them, not to me.