Ask HN: Why is recursion such a popular topic in interviews?
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 ] threadThe 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.
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.
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 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.