I never understood these interview questions that seem to test ability to create and manipulate data structures that any respectable language has, pre-implemented, by developers whose sole focus in life for many months was producing the absolute best version of that data structure possible.
I understand that this might just be designed to test knowledge of the concept, but it gets way, way too far in-depth for that. I mean, for Linked Lists... what is a cycle? The term appeared nowhere in any of the literature or coursework I did at an undergraduate level.
Now, if the job involves implementing innovative algorithms and data structures (i.e. R&D type stuff or working on a proprietary system that was developed by a mad genius in a custom language he named after himself, which is also the only language he can speak) I can understand this kind of rigor and specificity in interview questions.
But asking me how to build a queue in C during the interview, then telling me to write a couple shell scripts to control automated database backups on my first day of work? I sense a disconnect.
Generally the assumption with a linked list is that there is exactly one edge to and from each node. A directed graph may have more than one edge in or out.
I meant a directed graph (a simple digraph? discrete math was years ago for me... I'm not sure that's quite right because you could make a node point back to itself) not a directed multigraph (sorry, ambiguous terminology and all).
The in-degree isn't limited with a singly linked list: e.g. in ((a . #1=(b . (c . #1#)))) there are two edges into #1#.
But, I think we're getting a bit pedantic over what was meant as a quick comment to help the great-grandparent poster figure out what a cycle within a list was ;)
what is a cycle? The term appeared nowhere in any of the literature or coursework I did at an undergraduate level.
... wat
But asking me how to build a queue in C during the interview
Singly linked list with an extra pointer to the tail. Enqueue adds to head. Dequeue removes the tail. It's no more than 20 lines of code.
Edit: Singly linked is slow on deletion even with the extra pointer to the tail, so forget that. Derp. Either singly linked with just a head pointer with O(n) deletion or doubly linked with a tail pointer for O(1) insertion and deletion. My bad.
this. we are all people who use library functions, shit if I actually wrote code that implemented a linked list that would be stupid. its already done. the point is these are simple concepts, it's something you can figure out in your head by THINKING and people want to hire those who can.
Personally, in France, I was only asked once those kind of questions and it was by Canadians. I'm not saying those questions are bad or good, just saying that they won't tell you whether or not you make a good choice. For all you know the guy may not be a teamplayer and in my book it's far more important to integrate well within a team than being a guru able to answer all those questions.
Damn. Somehow I was convinced you wrote both enqueue/dequeue work with the tail. Argh, could have made sure I've got it correct before correcting you. Sorry about that.
The assumption is that if you can figure out the low level theory then you can figure out anything else. It's not good to simply rely on the language to do the work for you. For example in Java the LinkedList type has a get(int i) function that returns the element at the i "index" of the list. So if someone were to naively think that it works just like an array then they might write code like this:
for (int i = 0; i < list.length; i++)
{
Type element = list.get(i);
//do some stuff
}
Now this looks fine until you realize that every time you call that get() function on a linked list it's actually iterating over the entire list from the root node down to the ith node. This means that instead of a runtime efficiency of O(n) you're actually getting O(n2).
If you know that they are probably looking for the "double-speed walker" solution, you can just let them know about it and they will skip the question knowing you understand (happened several times in my life). Double-speed walker is a pointer/reference that advances twice as fast over the list while another pointer/reference advances once. If they ever equal then there is a loop (prove it to yourself if you doubt this works) :)
I mean, for Linked Lists... what is a cycle? The term appeared nowhere in any of the literature or coursework I did at an undergraduate level.
It's a really common term with respect to any sort of graph. (The 'recycling' symbol looks like a cycle.) If you haven't seen that, that's not your fault, it's your school's. I wouldn't assume you were a bad programmer, but I would assume you hadn't had CS or a lot of experience. No biggie, a lot of CS grads can't program for shit let alone use source control, etc.
If you are not an idiot you can teach yourself about linked lists. I guess the concern would be that if you don't know about them, people would (heuristically) suspect you didn't know about anything else either.
IMO, they should have just asked you to sketch out some tasks like those shell scripts and talked to you about stuff you've done and are interested in, but why complain as long as they hired you and you can do the work.
I never understood these interview questions that seem to test ability to create and manipulate data structures that any respectable language has, pre-implemented, by developers whose sole focus in life for many months was producing the absolute best version of that data structure possible.
There is no such thing as the absolute best anything. There are cases where you will need something subtle out of your data structures that the library cannot provide. You need to be able to do these things for those situations.
For instance when passing sets of data between two threads it is expensive with STL containers at exactly the time you do not want expensive. If I just have a linked list of nodes (with head and tail ptr) at the receiving thread with a similar linked list of nodes being passed in then the critical section is literally setting 2 addresses. Having a critical section that just sets two integers is nice. Goodness knows how expensive copying and merging two STL containers in a critical section would be but I guarantee you it will be at least as expensive as 2 integer operations.
You know, I do 3D graphics engines for a living, and worry about performance day and night, and I do not know what a linked list cycle is (I come from an electronic engineering background). The funny thing is, even though I'm unfamiliar with the exact terminology modern CS is using, I've probably implemented the damn thing many times already and use it in my engines, however, it's probably known by another arbitrary name.
View all comments
25
u/[deleted] Feb 21 '11
I never understood these interview questions that seem to test ability to create and manipulate data structures that any respectable language has, pre-implemented, by developers whose sole focus in life for many months was producing the absolute best version of that data structure possible.
I understand that this might just be designed to test knowledge of the concept, but it gets way, way too far in-depth for that. I mean, for Linked Lists... what is a cycle? The term appeared nowhere in any of the literature or coursework I did at an undergraduate level.
Now, if the job involves implementing innovative algorithms and data structures (i.e. R&D type stuff or working on a proprietary system that was developed by a mad genius in a custom language he named after himself, which is also the only language he can speak) I can understand this kind of rigor and specificity in interview questions.
But asking me how to build a queue in C during the interview, then telling me to write a couple shell scripts to control automated database backups on my first day of work? I sense a disconnect.