Live data from Hacker News

Linked List Problems (2002) [pdf]

cslibrary.stanford.edu

71–80 of 113 posts

Re: Linked List Problems (2002) [pdf]

#71
post #69

Earlier quoted context omitted.

Then why is tortoise and the hair credited to Floyd if it’s so trivial?

Attribution in science works in mysterious ways, and I don't claim to know how it works. In any case, I didn't say “trivial”. If you can only derive trivial things, then you shouldn't be a computer scientist.

Are you suggesting computer scientists should be able to derive non trivial results on job interviews? Really?

Re: Linked List Problems (2002) [pdf]

#72
post #35

Earlier quoted context omitted.

Yeah, until you need to remove an element from the middle in constant time - this is sometimes useful for things like the implementation of an LRU cache.

If you iterate over the list within an order of magnitude as often as you remove an element from the middle, an array will still be faster despite not having constant time removal, no matter the size of the list. To restate, if you have a workload where you iterate over your collection ~500 times, and remove an element from the middle ~1000 times, an array will usually outperform a linked list on a modern computer, n…

That's why I mentioned the LRU implementation. It does not iterate over the list, only adds elements to the front, deletes from the back and moves from the middle to the front. Refs to nodes are stored in a map, so iteration is not necessary to find an element.

Re: Linked List Problems (2002) [pdf]

#73

Earlier quoted context omitted.

As others have said, this is actually a, perhaps the best, canonical example of a terrible interview question [1]. [1] https://news.ycombinator.com/item?id=7953725

I liken these questions to a problem with a fancy car. If you have the exact tool it's trivial but if not damn near impossible. And a horrible interview question. It shows only that the interviewee has heard the question before or not.

Who couldn't figure out the idea behind tortoise and the hare? Maybe not the implementation, but the concept is probably the simplest way of going about it.

I am no programmer, and I managed to implement it not too long ago all on my own. It took no more than 10 minutes from idea to working implementation.

Re: Linked List Problems (2002) [pdf]

#74
post #71

Earlier quoted context omitted.

Attribution in science works in mysterious ways, and I don't claim to know how it works. In any case, I didn't say “trivial”. If you can only derive trivial things, then you shouldn't be a computer scientist.

Are you suggesting computer scientists should be able to derive non trivial results on job interviews? Really?

This amount of nontrivial, yes. Similarly, I'd expect a computer scientist to come up with a proof of correctness for either binary search or merge sort (the out of place variant) in ~30 minutes. It's not particularly difficult.

Re: Linked List Problems (2002) [pdf]

#75
post #73

Earlier quoted context omitted.

I liken these questions to a problem with a fancy car. If you have the exact tool it's trivial but if not damn near impossible. And a horrible interview question. It shows only that the interviewee has heard the question before or not.

Who couldn't figure out the idea behind tortoise and the hare? Maybe not the implementation, but the concept is probably the simplest way of going about it. I am no programmer, and I managed to implement it not too long ago all on my own. It took no more than 10 minutes from idea to working implementation.

As the linked article in parent post points out, this was an open problem in CS for 12 years before someone came up with the tortoise and hare algorithm. You really expect a candidate to come up with it from the top of their head, in a few minutes, during a stressful interview?

Re: Linked List Problems (2002) [pdf]

#76

One of my all-time favourites is this: suppose you have a linked list that eventually cycles: that is, the link of one of the nodes in the list points to a previous node in the list, but not necessarily the first node. Write a function to compute the cycle length of the cycle. Now if it was just a simple circular list, this would be trivial: set a pointer to a node, and move another pointer a node at a time until the…

"It is easy to see that they will eventually meet on the cycle. Once that happens, it is easy to count the cycle length."

Is that so?

Re: Linked List Problems (2002) [pdf]

#77

"Just say no to linked lists!" https://youtu.be/fHNmRkzxHWs?t=2099

He says because of cache misses due to each element being allocated individually. But then working with references is bad in general? If your vector stores references to objects it's bad? Your object fields point to strings - bad too. Should we ditch Lisp and Java? Note, data should not be continuous to stay in cache. Cache is more like paged virtual memory, it consists of cache lines. Before subscribing to the "neve…

Common Lisp has value types, it is not all about lists.

Likewise Java has primitive types, arrays and eventually will get value types, because they already feel the pressure in FinTech of not having them.

Re: Linked List Problems (2002) [pdf]

#79
post #30

Earlier quoted context omitted.

I mostly agree with this, however if the job requires a C.S. degree or equivalent and you assume all qualified candidates have been exposed to this, then perhaps it can be a useful question for testing how well you can explain a solution. Just look at how varied and complicated some of the explanations are for this out there. Some take mathematical approaches, others (me) try to boil it down to a few intuitive senten…

Unless you're interviewing Dijkstra, it's a ridiculous question to ask. Anyone who's heard it before knows the answer instantly (I knew the answer before I even finished reading the description) and anyone unfamiliar with it will likely flail.

I’m not convinced anyone unfamiliar would likely fail. A pretty obvious solution is to just have a list of all nodes you’ve been to, and check if the current node is in that list. Not the most optimal solution, but one I’d imagine a lot of decent programmers would be able to come up with.

Not saying it’s a good interview question, just that most good programmers shoukd be able to come up with some form of answer if they understand linked lists.

Re: Linked List Problems (2002) [pdf]

#80
post #62

Earlier quoted context omitted.

How does one, then, get an insight into the candidate's problem-solving ability in general?

By working with them on a number of non-trivial problems over the course of some time, usually measurable in weeks or months at least.

OK, I wholeheartedly agree with that. I was thinking, though, that discussing a problem such as the one with the linked list at least would give one sample point of the candidate's ability to reason. In any case, what are you supposed to do if you are restricted to making your decision based on interviews?
Post reply on HN