Ask HN: Why is recursion such a popular topic in interviews?

4 points by don_draper ↗ HN
I'm a full stack developer and I rarely run into the need to use recursion to solve a problem. So why do so many interviewers like to ask questions that involve a solution that uses recursion?

9 comments

[ 3.2 ms ] story [ 29.0 ms ] thread
I believe the idea is something like http://www.joelonsoftware.com/articles/ThePerilsofJavaSchool...

The idea that if you want to filter out people who aren't going to be good software devs there are two concepts to test. The first is pointers and the second is recursion.

well done - the perfect answer - with Joel adding the detail.
Thanks for a Joel article I hadn't read before. Two of my favorite class projects fell heavily into what he mentioned, implementing FAT12 in C for the OS course, and implementing a scheme interpreter in scheme for the programing language concepts course. Although call/cc still haunts my dreams.
>>I think it's just a necessary culling of the people who aren't going to be happy or successful in programming careers.

Thanks for the article, but he is wrong on this point. I have been programming for 17 years and I a) probably wouldn't do well if given an test on algorithms b) have many happy customers that would vouch for me. In 2013 I don't need to know how to traverse through a linked list to write web software that pleases clients. The thing about needing to know pointers and algorithms to have a successful career in programming is wrong. The closest thing to algorithms I need to know is that I need indexes in my database if the queries get slow. I would argue most developers need to learn marketing more than how to program a fibonacci sequence using recursion.

"That's just like...aa.. your opinion man." - The Big Lebowski

Spoiler: every set of instructions you code is an algorithm. An algorithm is not something magical, it's just a series of steps that lead you to a result.

Knowing different algorithms and knowing which one is better for you allows you to create the best solution for a problem. For example, having to display a sorted list of contacts or a list of geographic locations can be achieved in many ways. Depending on what algorithm you use for sorting that list you can have a result in 1 second or 2 hours. Says that you can be a programmer without the use of algorithms or pointers is like saying you can be a chef without knowing how to cut onions.

I rather dislike recursion, I find it to be the remedial hammer of software development. Sure there are some use cases, but most problems are solvable in a more efficient manner, such as the use of formulas. Even if a formula is not viable, there are other methods that produce better maintainable code. I label recursion as 'use as a last resort'.
I think that everyone felt really smart the first time they "got" recursion. Then that feeling has followed them around but switched position assuming that someone isn't smart UNLESS they get recursion. I think recursion is a really clever way to solve a select few problems but I hate cleverness most of the time when I see it in code. Recursion is a neat concept but IMO with the multitude of relevant questions that could be asked of a developer it should be further down on most interviewers lists.
What does "the use of formulas" mean? Could you give a concrete example of what you're referring to?
My two cents:

I think it's because understanding recursion involves a good understanding of a bunch of stuff. You have to know about the different scopes of variables (global, local), how the variables are stored, how does a stack work, etc.

It also challenges you to understand why it's not a good idea to use recursion and to find an iterative solution to your problem.

Most interviewers like to cover more areas with one question.