| I knew CS graduates who loved parsing theory and could implement some basic C compilers, and I knew some who didn't know what a SCSI controller was. You get out of your education what you put into it. 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. Reference counts can get leaks if you have two objects referencing each other with to path to either, but what I didn't realize is that Java hasn't used reference counts in a really long time. It does a search from each root (typically a thread) down the object tree; and it breaks things into young/old (eden space and .. something else) so long lived objects don't get searched as often. I learned all of that during the interview lunch break when I looked it up on my phone. One of my good friends wrote a compile time GC for GO and did this PhD dissertation on it, and he probably would have got this question right. But if it's not in your field, well the problem space for problems is pretty fucking large. 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: https://penguindreams.org/projects/graphmapper/ 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. I'd move breath first and error out if I discovered the same hash/unique key .. which of course would give me a hash the size of the tree. Unless there's a way to mark the data structure, you now have a second structure the size of your key space. I'm sure there are better solutions, but I wouldn't expect a senior program to know them off the top of their head, unless you're hiring really specifically for a position writing routing algorithms or looking for a senior airport transit architect. |
https://en.wikipedia.org/wiki/Cycle_detection#Floyd%27s_Tort...
If you come up with something else (like tagging nodes), you get a strike for inefficiency.
It looks simple enough to feel smug about once you know it, at the same time there's near zero chance the interviewers could come up with this algorithm independently without prior knowledge.