There are already some really good answers, but hopefully I can add something. In my mind, you have to look at this question in the broader context of
"What constitutes an effective interview?'
or even more simply put
"How do you know the person you're interviewing will 'work out'?"
As a dev manager I have very limited options. In an ideal world and given infinite time and resources, you would bring in every potential new hire, have him work for a month or so, and make an assessment at the end of this period as to whether he was worth keeping. That's not feasible, however, for a number of reasons:
- Bringing in a new person is disruptive to existing staff
- No one will leave his current jobs for a new one if it's not a guaranteed position
- Companies would not want to foot the bill for ramping someone up, only to subsequently let him go
- If you did this for everyone, you'd end up wasting a tremendous amount of time on people who were completely unsuitable
A slightly more practical version of this is to provide internships to college students or recent grads. This way you can see how the person works out, build a reslationship, and if he's really outstanding extend an offer.
In most cases, however, it's infeasible to just bring someone in. So, then you're back at some type of interview. The questions one can ask within a limited time-frame are necessarily circumscribed and somewhat contrived. It's difficult to get a feel for someone's abilities in a very short window, so you have to decide how close you can come to the what you might get from the shadowing exercise described above while still limiting the amount of time and resources you invest in the prospective employee.
In my experience, the absolute best test it to come up with a simple programming exercise (something that most people should be able to solve completely in a 2-3 hours), give the candidate a laptop, access to his IDE of choice, Google, and any other resources he would have when actually doing his job. This is the closest you'll be able to come to assessing him under 'real world' conditions. Of course, the exercise will likely still be a bit contrived (though if possible it should be a reflection of similar work to what he'll really be doing). Give him incomplete information, maybe a few misqueues. Put him in a room, give him your phone number, and tell him he can call you at any time, and you'll answer any question he has.
At the end, he may or may not have answered the question completely. But look at what he's done. Is the work conceptually sound? Does his code look reasonable? Did he ask intelligent questions? Did he notice the traps you set for him and ask for clarification?
Usually, that's the last step in the interview process. Back to the original question, I also like to get a more face-to-face feel for the candidates' problem solving skills and knowledge.
As other's have mentioned, 8 out of 10 people who submit a resume can't even solve the simplest of questions in their language of choice. I never cease to be amazed by this. I can't even count the number of people I've interviewed who had resumes listing '8 years of J2EE' experience and yet could barely program 'Hello World' in Java. As a result, I've come to largely ignore resumes. Coversely, some people who have really crappy resumes, do phenomenally in an interview. Unless the resume is just atrocious almost every prospective candidate gets a phone screen. In lieu of anything better, I'll ask a few basic data structure and algorithmic questions.
Again, as other people have mentioned, a question about an algorithm shouldn't be asked as a test to see if the person can memorize things. I'd never ask 'Tell me the QuickSort algorithm?' then if the person couldn't remember, disqualify him. No, these questions are asked to see a person's thought process, get a sense that they understand the basics of computer science (for example, if a person can't give me the basics of linked lists, arrays, and hash tables he's really going to have an uphill battle). The thing is as contrived as such questions are, they are the best thing we've got. If I ignore resumes, I need some way to cull the really atrocious people so I don't waste 3-4 hours on an onsite. And when a candidate makes it to the onsite, I need a way to cull the people who shouldn't have made it past the screen. It's an escalating scale. Again, as contrived as most questions are, questions that devlve into the fundamentals of computer science, ones that illustrative a person's problem solving skills, and that show me the person can think are the best tool I have after seeing how the person performs in the real world.
The worst interview questions to me are ones tha require rote recital of facts. I've always had an uphill battle with HR departments and my bosses arguing that I don't care if a person knows Hibernate or Spring or whatever technologies we happen to use. I care about someone who can think critically, has a firm command of the basics (including efficiency trade-offs of algorithms & data structures) and who seems to have a geniuine interest in learning new things.
That will trump pre-existing knowledge every time.